命令

详解

kubectl get services –all-namespaces -o wide

查看集群内的nodeport端口占用

kubectl get svc -n kube-system

查看端口映射

kubectl get secret -n kube-system

查看 secret

kubectl describe secret kubernetes-dashboard –namespace=kube-system

查看 token

journalctl -xefu kubelet

k8s 无法启动,查看日志,查找Failed

kubectl logs name –namespace=kube-system

查看pod错误日

kubectl apply -f kubernetes-dashboard.yaml

对资源进行配置

kubectl create -f nginx-deployment.yaml

创建deployment资源

kubectl get deploy

查看deployment

kubectl get rs

查看ReplicaSet

kubectl get pods –show-labels

查看pods所有标签

kubectl get pods -l app=nginx

根据标签查看pods

kubectl set image deployment/nginx-deployment nginx=nginx:1.11

滚动更新镜像1

kubectl edit deployment/nginx-deployment

滚动更新镜像2

kubectl apply -f nginx-deployment.yaml

滚动更新镜像3

kubectl rollout status deployment/nginx-deployment

实时观察发布状态

kubectl rollout history deployment/nginx-deployment

查看deployment历史修订版本 –to-revision=3

kubectl rollout undo deployment/nginx-deployment

回滚到以前版本 –to-revision=3

kubectl scale deployment nginx-deployment –replicas=10

扩容deployment的Pod副本数量

kubectl autoscale deployment nginx-deployment –min=10 –max=15 –cpu-percent=80

设置启动扩容/缩容

kubectl get pods

列出所有运行的Pod信息

kubectl get pods -o wide

列出Pod以及运行Pod节点信息

kubectl get replicationcontroller web

列出指定NAME的 replication controller信息

kubectl get -o json pod web-pod-13je7

以JSON格式输出一个pod信息

kubectl get -f pod.yaml -o json

以“pod.yaml”配置文件中指定资源对象和名称输出JSON格式的Pod信息

kubectl get -o template pod/web-pod-13je7 –template={{.status.phase}}

返回指定pod的相位值

kubectl get rc,services

列出所有replication controllers和service信息

kubectl get rc/web service/frontend pods/web-pod-13je7

按其资源和名称列出相应信

kubectl get all

列出所有不同的资源对象

kubectl get namespaces

查看名称空间