状态查询
kubectl cluster-info
systemctl status kube-apiserver
systemctl status kubelet
systemctl status kube-proxy
systemctl status kube-scheduler
systemctl status kube-controller-manager
systemctl status docker
kubectl get apiservice
node相关
kubectl get namespaces
kubectl label nodes 10.126.72.31 points=test
kubectl get nodes
kubectl get componentstatuses
kubectl cordon k8s-node1
kubectl uncordon k8s-node1
查询
kubectl get nodes
kubectl get -f xxx-yaml/
kubectl get all
kubectl get resourcequota
kubectl get endpoints
kubectl get po -n kube-system
kubectl get pods -o wide
kubectl get pod -o wide
kubectl get svc
kubectl get services
kubectl get pods -l app=nginx -o yaml|grep podIP
kubectl describe pod xxx
kubectl get events
删除所有pod
kubectl delete pods --all
kubectl delete pods,services -l name=<lable-name>
kubectl delete deployments kubernetes-dashboard --namespace=kube-system
kubectl delete services kubernetes-dashboard --namespace=kube-system
kubectl delete deployment kafka-1
kubectl delete rs --all && kubectl delete rc --all
kubectl delete deployment kafka-1 --grace-period=0 --force
滚动
kubectl apply -f xxx.yaml --record
kubectl rollout undo deployment javademo
kubectl rollout history deployment {名称}
查看日志
# 查看指定镜像的日志
kubectl logs -f kube-dns-699984412-vz1q6 -n kube-system
kubectl logs
#指定其中一个查看日志
kubectl logs kube-dns-699984412-n5zkz -c kubedns
kubectl logs kube-dns-699984412-vz1q6 -c dnsmasq
kubectl logs kube-dns-699984412-mqb14 -c sidecar
# 看日志
journalctl -f
扩展
# 扩展副本
kubectl scale rc xxxx
kubectl scale rc mysql
kubectl scale
执行
nohup kubectl proxy --address='10.1.70.247' --port=8001 --accept-hosts='^*$' >/dev/null 2>&1 &
kubectl exec kube-dns-699984412-vz1q6 -n kube-system -c kubedns ifconfig
kubectl exec kube-dns-699984412-vz1q6 -n kube-system -c kubedns ifconfig /bin/bash
kubectl exec kube-dns-4140740281-pfjhr -c etcd --namespace=kube-system etcdctl get /skydns/local/cluster/default/redis-master
无限循环命令
while true; do sleep 1; done
资源管理
kubectl rollout pause deployment xxx
kubectl rollout resume deployment xxx
kubectl set resources deployment xxx -c=xxx
kubectl patch storageclass <your-class-name> -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
其他
kubectl explain pod.spec
kubectl create -f dashboard-controller.yaml
kubectl delete -f dashboard-dashboard.yaml
kubectl apply -f xxx.yaml
kubectl replace -f xxx.yaml
kubectl exec xxx env
kubectl exec busybox -- nslookup kube-dns.kube-system
systemctl status kube-proxy -l
kubectl get serviceaccount/kube-dns --namespace=kube-system -o yaml|grep token
复杂便捷的exec
kubectl exec -ti -n nginx `kubectl get pods -n nginx|grep php-app|awk '{print $1}'` /bin/bash
kubectl exec -ti -n nginx `kubectl get pods -n nginx|grep nginx|awk '{print $1}'` /bin/bash
kubectl get pods -n nginx|grep php-app|awk '{print $1}'|xargs -I {} kubectl exec -ti {} -n nginx /bin/bash