# command命令,entity实体/资源
kubectl ${command} ${entity}
- apply
- get
- config
- create
- delete
- describe
- labels
- replace
- view
- namespaces(ns)
- deployments(deploy)
- nodes
- pod
- secrets
- configmap(cm)
- daemonsets(ds)
- pv
- pvc
- service(svc)
kubectl config view
- -A : 表示获取全部命名空间的对象
kubectl get namespace # namespace可简写为ns
kubectl create namespace <insert-namespace-name-here>
kubectl delete namespaces <insert-some-namespace-name>
kubectl config view | grep namespace
kubectl config set-context --current --namespace=<insert-namespace-name-here>
kubectl get nodes
kubectl get nodes --show-labels
# 展示标签
kubectl describe node <node-name>
kubectl label nodes <node-name> <label-key>=<label-value>
kubectl label nodes <node-name> <label-key>-
kubectl get pods
kubectl get pods -A
kubectl get pods -n <namespace>
kubectl replace --force -f {yaml文件}
kubectl get pod {podname} -n {namespace} -o yaml | kubectl replace --force -f -
kubectl delete pod {podname}
kubectl get secrets
kubectl get secrets -A
基于用户名密码创建
kubectl create secret docker-registry <key name> --docker-server=<cluster_CA_domain>:8500 --docker-username=<user_name> --docker-password=<user_password> --docker-email=<user_email>
基于docker配置文件创建
kubectl create secret generic harborsecret --from-file=.dockerconfigjson=/root/.docker/config.json --type=kubernetes.io/dockerconfigjson
kubectl get secret {secret name} -o yaml
kubectl get cm -A
kubectl get cm <configmap> -o yaml
kubectl create cm {configmap name} --from-file=/path/file -n {namespace}
kubectl delete cm {configmap name} -n {namespace}
输出指定的一个/多个资源的详细信息
kubectl describe pod {podname} # 描述指定pod
kubectl desctibe pods # 描述所有pod
获取所有可用API版本
kubectl api-versions
获取api权限列表
kubectl api-resources
检查证书是否过期
kubeadm certs check-expiration