常用操作

  1. [查看版本]
  2. $ kubectl version
  3. Client Version: version.Info
  4. {
  5. Major: "1",
  6. Minor: "5",
  7. GitVersion: "v1.5.2",
  8. GitCommit: "269f928217957e7126dc87e6adfa82242bfe5b1e",
  9. GitTreeState: "clean",
  10. BuildDate: "2017-07-03T15:31:10Z",
  11. GoVersion: "go1.7.4",
  12. Compiler: "gc",
  13. Platform: "linux/amd64"
  14. }
  15. Server Version: version.Info
  16. {
  17. Major: "1",
  18. Minor: "5",
  19. GitVersion: "v1.5.2",
  20. GitCommit: "269f928217957e7126dc87e6adfa82242bfe5b1e",
  21. GitTreeState: "clean",
  22. BuildDate: "2017-07-03T15:31:10Z",
  23. GoVersion: "go1.7.4",
  24. Compiler: "gc",
  25. Platform: "linux/amd64"
  26. }
  27. [显示集群信息]
  28. $ kubectl cluster-info
  29. Kubernetes master is running at http://localhost:8080
  30. To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

NODE

  1. [查看集群Node数量]
  2. $ kubectl get nodes
  3. NAME STATUS AGE
  4. k8s-node-1 Ready 1h

POD

  1. [查看POD]
  2. $ kubectl get pods
  3. NAME READY STATUS RESTARTS AGE
  4. my-nginx-379829228-cwlbb 0/1 ContainerCreating 0 20s
  5. my-nginx-379829228-czk6w 1/1 Running 0 20s
  6. http-706590874-bj47j 0/1 Terminating 0 24m
  7. [删除POD -> 根据配置,会自动生成]
  8. $ kubectl delete pod my-nginx-379829228-cwlbb
  9. []
  10. $ 删除部署的my-nginx服务。彻底删除pod
  11. [查看 POD 服务详情信息]
  12. $ kubectl describe pod http-706590874-bj47j
  13. Name: http-706590874-bj47j
  14. Namespace: default
  15. Node: k8s-node-1/
  16. Labels: pod-template-hash=706590874
  17. run=http
  18. Status: Terminating (expires Sun, 09 Jun 2019 21:08:00 +0800)
  19. Termination Grace Period: 30s
  20. IP:
  21. Controllers: ReplicaSet/http-706590874
  22. Containers:
  23. http:
  24. Image: http
  25. Port: 80/TCP
  26. Volume Mounts: <none>
  27. Environment Variables: <none>
  28. Conditions:
  29. Type Status
  30. PodScheduled True
  31. No volumes.
  32. QoS Class: BestEffort
  33. Tolerations: <none>
  34. Events:
  35. FirstSeen LastSeen Count From SubObjectPath Type Reason Message
  36. --------- -------- ----- ---- ------------- -------- ------ -------
  37. 25m 25m 1 {default-scheduler } Normal Scheduled Successfully assigned http-706590874-bj47j to k8s-node-1
  1. [查看已部署]
  2. $ kubectl get deployments
  3. NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
  4. http 1 1 1 0 26m
  5. my-nginx 1 1 1 0 11m
  6. [删除部署的服务, 彻底删除pod]
  7. $ kubectl delete deployment my-nginx

镜像运行

  1. [镜像运行]
  2. $ kubectl run my-nginx --image=nginx --replicas=2 --port=80
  1. # docker run
  2. $ docker run -d -e DOMAIN=cluster --name my-nginx -p 80:80 nginx
  3. $ kubectl run my-nginx --image=nginx --port=80 --env="DOMAIN=cluster"
  4. # docker ps
  5. $ docker ps
  6. $ kubectl get pods
  7. # docker exec
  8. $ docker exec [容器id] ls
  9. $ kubectl exec [pod_id] ls
  10. # docker exec 交互式
  11. $ docker exec -it [容器id] /bin/sh
  12. $ kubectl exec -it [pod_id] -- /bin/sh
  13. # docker info
  14. $ docker info
  15. $ kubectl cluster-info