本文共 3254 字,大约阅读时间需要 10 分钟。
kubectl get pods
kubectl get pods --all-namespaces
kubectl get pods -o wide
kubectl get pod mypod -o yaml
kubectl describe pods
kubectl get pods --sort-by='.status.containerStatuses[0].restartCount'
kubectl get pods --show-labels
kubectl get pods -l "label=value"
kubectl port-forward pod mypod 8080:80
kubectl exec pod mypod -- sh
kubectl exec pod mypod -c containername -- sh
kubectl get secrets
kubectl get secrets --all-namespaces
kubectl get secrets -o wide
kubectl get secret mysecret -o yaml
kubectl get services
kubectl get services --all-namespaces
kubectl get services -o wide
kubectl get service myservice -o yaml
kubectl describe services
kubectl get services --show-labels
kubectl get services -l "label=value"
kubectl set image deployment/myapp myapp-image=yourimageversion
kubectl rollout history deployment/myapp
kubectl rollout undo deployment/myapp
kubectl rollout undo deployment/myapp --to-revision=2
kubectl rollout status -w deployment/myapp
kubectl rollout restart deployment/myapp
kubectl edit deployment/myapp
kubectl scale --replicas=3 deployment/myapp
kubectl delete pod mypod
kubectl config get-contexts
kubectl config current-context
###切换到其他集群
kubectl config use-context mycluster
###更改当前上下文的命名空间
kubectl config set-context --current --namespace= namespace
kubectl logs mypod
kubectl logs -l "label=value"
kubectl logs mypod --previous
kubectl logs mypod -c mycontainer
kubectl logs -f mypod
kubectl logs -f -l "label=value" --all-containers
kubectl logs mypod --v=0:9
kubectl get deployment
kubectl get deployment --all-namespaces
kubectl get deployment -o wide
kubectl get deployment mydeployment -o yaml
kubectl describe deployment
kubectl get deployment -l "label=value"
kubectl get ingress
kubectl get ingress --all-namespaces
kubectl get ingress -o wide
kubectl get ingress myingress -o yaml
kubectl describe ingress
kubectl get ingress -l "label=value"
kubectl apply -f ./manifest.yaml
kubectl apply -f ./manifest1.yaml -f ./manifest2.yaml
kubectl apply -f ./ manifests/
kubectl apply -f https://example.com/manifest.yaml
kubectl create deployment mydeployment --image=yourimage
kubectl cordon node mynode
kubectl drain node mynode
kubectl uncordon node mynode
kubectl top node mynode
###查看集群信息
kubectl cluster-info
###导出集群状态到标准输出
kubectl cluster-info dump
###列出可用的Kubernetes资源
kubectl api-resources
###列出当前命名空间内的可用资源
kubectl api-resources --namespaced=true
转载地址:http://jlryk.baihongyu.com/