#基础命令
kubectl get po/svc/cm/rc : 查看容器
kubectl describe po name :查看详情
kubectl delete po name :删除资源
-o wide : 多显示几列信息
--all-namespaces : 所有命名空间
-n name : 指定命名空间(default可以不带此参数)
kubectl apply/create -f aaa.yaml
: 执行yml文件
kubectl exec 容器名称 -it -- bash : 进入容器
exit : 退出
#资源类型
all
certificatesigningrequests (aka 'csr')
clusterrolebindings
clusterroles
componentstatuses (aka 'cs')
configmaps (aka 'cm')
controllerrevisions
cronjobs
customresourcedefinition (aka 'crd')
daemonsets (aka 'ds')
deployments (aka 'deploy')
endpoints (aka 'ep')
events (aka 'ev')
horizontalpodautoscalers (aka 'hpa')
ingresses (aka 'ing')
jobs
limitranges (aka 'limits')
namespaces (aka 'ns')
networkpolicies (aka 'netpol')
nodes (aka 'no')
persistentvolumeclaims (aka 'pvc')
persistentvolumes (aka 'pv')
poddisruptionbudgets (aka 'pdb')
podpreset
pods (aka 'po')
podsecuritypolicies (aka 'psp')
podtemplates
replicasets (aka 'rs')
replicationcontrollers (aka 'rc')
resourcequotas (aka 'quota')
rolebindings
roles
secrets
serviceaccounts (aka 'sa')
services (aka 'svc')
statefulsets (aka 'sts')
storageclasses (aka 'sc')
#查看所有命名空间的pod:
kubectl get po -o wide --all-namespaces
#查看所有命名空间的rc(其他资源类似,把rc换成其他资源即可):
kubectl get rc -o wide --all-namespaces
#查看kube-system命名空间的pod:
kubectl get po -o wide -n kube-system
#查看defalut命名空间的pod(default命名空间的可以省略 -n default,其他资源也一样):
kubectl get po -o wide
#根据yaml文件创建资源:
kubectl apply -f aaa.yaml
或
kubectl create -f aaa.yaml
#根据yaml文件删除创建资源:
kubectl delete -f aaa.yaml
#获取pod(这里以kube-proxy-7gkfk为例,kube-proxy-7gkfk是pod名字)详细信息:
kubectl describe po kube-proxy-7gkfk -n kube-system
#获取某rc(这里以mysql为例,mysql是rc名字)详细信息:
kubectl describe rc mysql
#查看某pod(这里以etcd-see-k8s-master1为例,etcd-see-k8s-master1为pod名字)日志:
kubectl logs etcd-see-k8s-master1 -n kube-system
#查看帮助
kubectl help