1.部署
kubectl create -f xxx.yaml
Pod相关
2.删除Pod
# 删除Pod
kubectl delete pod {pod_name}
# 删除Deploy
kubectl delete deploy {deploy_name}
3.查看Pod
# 查看Pod列表
kubectl get pods -n kube-system
# 查看某个Pod信息
$ kubectl get pod etcd-kube-master3 -n kube-system
NAME READY STATUS RESTARTS AGE
etcd-kube-master3 1/1 Running 0 24d
#查看Pod详细信息
$ kubectl get pod etcd-kube-master3 -n kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
etcd-kube-master3 1/1 Running 0 24d 10.120.200.3 kube-master3 <none> <none>
#查看Pod详细信息
kubectl describe pod {pod-name} -n kube-system
4.查询Pod
kubectl get pod --selector name=redis -n kube-system
查看日志
kubectl logs {pod-name} -n kube-system
在Pod上执行命令
kubectl exec {pod-name} {cmd} -n kube-system
# 交互式
kubectl exec -it {pod-name} {cmd} -n kube-system bash
服务相关
查看服务
$ kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP 24d
kubernetes-dashboard NodePort 10.109.40.189 <none> 443:30110/TCP 24d
查看Node列表
$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
kube-master1 Ready master 24d v1.13.1
kube-master2 Ready master 24d v1.13.1
kube-master3 Ready master 24d v1.13.1
kube-node1 Ready <none> 24d v1.13.1
kube-node2 Ready <none> 24d v1.13.1
kube-node3 Ready <none> 24d v1.13.1
集群相关
查看版本
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:39:04Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.1", GitCommit:"eec55b9ba98609a46fee712359c7b5b365bdd920", GitTreeState:"clean", BuildDate:"2018-12-13T10:31:33Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"linux/amd64"}
Deployment相关
查看Deployment列表
$ kubectl get deployments -n kube-system
NAME READY UP-TO-DATE AVAILABLE AGE
coredns 2/2 2 2 24d
kubernetes-dashboard 1/1 1 1 24d
Label相关
添加Label
kubectl label pod {pod-name} app=v1
根据Label查询
kubectl get pods -l app=v1 -n kube-system