Kubernetes 常用命令

查看版本:

$ kubectl version

查看集群状态:

$ kubectl cluster-info

查看节点:

$ kubectl get nodes

查看 deployment:

$ kubectl get deployment

查看 pod:

$ kubectl get pods

查看 pod 详情:

$ kubectl describe pods

查看 pod 日志:

$ kubectl logs $POD_NAME

进入 pod 中容器的 bash :

$ kubectl exec -it $POD_NAME

创建一个服务:

$ kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080

列出当前的 service :

$ kubectl get services

查看 service 详情:

$ kubectl describe services/kubernetes-bootcamp

查看 deployment:

$ kubectl describe deployment

根据 label 查看 pod 和 service:

$ kubectl get pods -l run=kubernetes-bootcamp
$ kubectl get services -l run=kubernetes-bootcamp

设置 label:

$ kubectl label pod [pod-name] [label-name]

// 示例
$ kubectl label pod kubernetes-bootcamp-598f57b95c-w824k app=v1

删除 service:

$ kubectl delete service -l [pod-label]

// 示例
$ kubectl delete service -l run=kubernetes-bootcamp

删除 pod:

kubectl delete pod [pod-name]

批量删除 pod:

kubectl get pod | grep [过滤关键字] | awk '{print $1}' | xargs kubectl delete pod

你可能感兴趣的:(Kubernetes 常用命令)