kubernetes常用命令

kubectl

source <(kubectl completion bash) #命令补全

启动-状态

  1. master
  2. systemctl daemon-reload
  3. systemctl start kube-apiserver
  4. systemctl start kube-controller-manager
  5. systemctl start kube-scheduler
  6. etcd
  7. systemctl start etcd.service
  8. client
  9. systemctl start kube-proxy -l
  10. systemctl start docker -l
  11. systemctl start kubelet -l
  12. status
  13. systemctl status etcd.service
  14. systemctl status kube-apiserver -l
  15. systemctl status kube-controller-manager -l
  16. systemctl status kube-scheduler
  17. systemctl status kube-proxy -l
  18. systemctl status docker -l
  19. systemctl status kubelet -l

常用命令

  1. kubectl get pods
  2. kubectl get rc
  3. kubectl get service
  4. kubectl get componentstatuses
  5. kubectl get endpoints
  6. kubectl cluster-info
  7. kubectl create -f redis-master-controller.yaml
  8. kubectl delete -f redis-master-controller.yaml
  9. kubectl delete pod nginx-772ai
  10. kubectl logs -f pods/heapster-xxxxx -n kube-system #查看日志
  11. kubectl scale rc redis-slave --replicas=3 #修改RC的副本数量,来实现Pod的动态缩放
  12. etcdctl cluster-health #检查网络集群健康状态
  13. etcdctl --endpoints=https://192.168.71.221:2379 cluster-health #带有安全认证检查网络集群健康状态
  14. etcdctl member list
  15. etcdctl set /k8s/network/config '{ "Network": "10.1.0.0/16" }'
  16. etcdctl get /k8s/network/config

基础进阶

  1. kubectl get services kubernetes-dashboard -n kube-system #查看所有service
  2. kubectl get deployment kubernetes-dashboard -n kube-system #查看所有发布
  3. kubectl get pods --all-namespaces #查看所有pod
  4. kubectl get pods -o wide --all-namespaces #查看所有pod的IP及节点
  5. kubectl get pods -n kube-system | grep dashboard
  6. kubectl describe service/kubernetes-dashboard --namespace="kube-system"
  7. kubectl describe pods/kubernetes-dashboard-349859023-g6q8c --namespace="kube-system" #指定类型查看
  8. kubectl describe pod nginx-772ai #查看pod详细信息
  9. kubectl scale rc nginx --replicas=5 # 动态伸缩
  10. kubectl scale deployment redis-slave --replicas=5 #动态伸缩
  11. kubectl scale --replicas=2 -f redis-slave-deployment.yaml #动态伸缩
  12. kubectl exec -it redis-master-1033017107-q47hh /bin/bash #进入容器
  13. kubectl label nodes node1 zone=north #增加节点lable值 spec.nodeSelector: zone: north #指定pod在哪个节点
  14. kubectl get nodes -lzone #获取zone的节点
  15. kubectl label pod redis-master-1033017107-q47hh role=master #增加lable值 [key]=[value]
  16. kubectl label pod redis-master-1033017107-q47hh role- #删除lable值
  17. kubectl label pod redis-master-1033017107-q47hh role=backend --overwrite #修改lable值
  18. kubectl rolling-update redis-master -f redis-master-controller-v2.yaml #配置文件滚动升级
  19. kubectl rolling-update redis-master --image=redis-master:2.0 #命令升级
  20. kubectl rolling-update redis-master --image=redis-master:1.0 --rollback #pod版本回滚
 
 
posted @ 2017-07-14 13:38  阅尽世间繁华  阅读(8310)  评论(0编辑  收藏  举报