无论受到的困顿有多艰难,只要还有家在,就应时刻准备着重返工作岗位。
怕手生了,整理了一些 Kubernetes 的管理命令:
kubectl get nodes
kubectl get nodes -o wide
kubectl get pod
kubectl get pod -o wide
kubectl get pod -n kube-system
kubectl get pod -n kube-system podName
kubectl get pod -A
kubectl get pods -o yaml kubectl get pods -o json
kubectl get pod -A --show-labels
kubectl get pod -A --selector="k8s-app=kube-dns"
kubectl exec podName env
kubectl logs -f --tail 500 -n kube-system kube-apiserver-k8s-master
kubectl get svc -A
kubectl get svc -n kube-system
kubectl get cs
kubectl get cm -A
kubectl get sa -A
kubectl get ds -A
kubectl get deploy -A
kubectl get rs -A
kubectl get sts -A
kubectl get jobs -A
kubectl get ing -A
kubectl get ns
kubectl describe pod podName kubectl describe pod -n kube-system kube-apiserver-k8s-master
kubectl describe deploy -n kube-system coredns
kubectl top node kubectl top pod
kubectl cluster-info 或 kubectl cluster-info dump
kubectl -s https://172.16.1.110:6443 get componentstatuses
kubectl create -f xxx.yaml
kubectl apply -f xxx.yaml
kubectl apply -f <directory>
kubectl create namespace test
kubectl delete -f xxx.yaml kubectl delete -f <directory>
kubectl delete pod podName
kubectl delete pod -n test podName
kubectl delete svc svcName kubectl delete deploy deployName kubectl delete ns nsName
kubectl delete pod podName -n nsName --grace-period=0 --force kubectl delete pod podName -n nsName --grace-period=1 kubectl delete pod podName -n nsName --now
kubectl edit pod podName
kubectl exec -it podName -n nsName /bin/sh #进入容器 kubectl exec -it podName -n nsName /bin/bash #进入容器
kubectl label nodes k8s-node01 zone=north #为指定节点添加标签 kubectl label nodes k8s-node01 zone- #为指定节点删除标签 kubectl label pod podName -n nsName role-name=test #为指定pod添加标签 kubectl label pod podName -n nsName role-name=dev --overwrite #修改lable标签值 kubectl label pod podName -n nsName role-name- #删除lable标签
kubectl apply -f myapp-deployment-v2.yaml #通过配置文件滚动升级 kubectl set image deploy/myapp-deployment myapp="registry.cn-beijing.aliyuncs.com/google_registry/myapp:v3" #通过命令滚动升级 kubectl rollout undo deploy/myapp-deployment 或者 kubectl rollout undo deploy myapp-deployment #pod回滚到前一个版本 kubectl rollout undo deploy/myapp-deployment --to-revision=2 #回滚到指定历史版本
kubectl scale deploy myapp-deployment --replicas=5 # 动态伸缩 kubectl scale --replicas=8 -f myapp-deployment-v2.yaml #动态伸缩【根据资源类型和名称伸缩,其他配置「如:镜像版本不同」不生效】