语法
kubectl <command> <type> <name> <flags>
command:
create/delete/get/describe/apply
type:
资源对象类型,严格区分大小写
daemonsets 缩写ds
deployments
events 缩写ev
endpoints 缩写ep
horizontalpodautoscalers 缩写hpa 水平扩展
ingresses 缩写ing
jobs
nodes 缩写no
pods 缩写po
namespaces 缩写ns
persistentvolumes 缩写pv
persistentvolumes 缩写pvc 创建卷组
resourcequotas 缩写quota
replicationcontrollers 缩写 rc
secrets
service 缩写svc
serviceaccounts 缩写sa
name:
资源对象名称,严格区分大小写
flags:
可选参数
-n 指定namespace
kubectl子命令
annotate 添加或更新资源对象的信息
apply 从配置文件更新资源对象
kubectl apply -f <filename>
attach 连接一个正在运行的pod到container
kubectl attach pod -c <container>
cluster-info 显示集群信息
kubectl cluster-info
completion 输出shell命令执行后的返回码
kubectl completion bash
config 修改kubeconfig配置文件
create 从配置文件创建资源对象
kubectl create -f xxxx.yml
delete 从配置文件删除资源对象
kubectl delete -f xxxx.yml
describe 查看资源对象详细信息
kubectl describe pods -n <命名空间名>
edit 编辑资源对象属性
kubectl edit sa admin -n kube-system
exec 执行一个容器中的命令
kubectl exec <pod名> ls -n <命名空间名称>
kubectl exec coredns-7688bbffb9-4rd6j ls -n kube-system
label 为了资源对象创建label 方便调度
kubectl label node node1.example.com hello
查看 kubectl get nodes --show-labels