kubectl cmd

集群资源查看

kubectl get nodes    #查看节点状态
kubectl get cs       #kubectl检查组件健康状态
kubectl get pods 
kubectl get all
kubectl get svc $serviceames
kubectl get ep
kubectl create -f nginx.yaml
kubectl delete -f nginx-deployment.yaml
kubectl run nginx --image=nginx:1.16 --port=80 --replicas=2
kubectl expose deployment/nginx  --type="NodePort" --port=80 --name=nginx  #创建Service对象以将应用程序"暴露"于网络中
kubectl get pods -l app=nginx #获取所有匹配app: nginx标签的Pod
kubectl describe pod nginx-deployment-67594d6bf6-9gdvr   # 查看API对象的细节
kubectl exec -it nginx-deployment-5c678cfb6d-lg9lw -n $namespace-- /bin/bash
kubectl exec -it  <pod-name> -n <namespace>  -- /bin/bash   进入pod
kubectl exec -it  <pod-name> -n <namespace> -c <container-name> -- /bin/bash 进入pod中指定容器

# 集群资源查询
kubectl get cs                          # 查看集群状态
kubectl get nodes                       # 查看集群节点信息
kubectl get ns                          # 查看集群命名空间
kubectl get svc -n kube-system          # 查看指定命名空间的服务
kubectl get pod <pod-name> -o wide      # 查看Pod详细信息
kubectl get pod <pod-name> -o yaml      # 以yaml格式查看Pod详细信息
kubectl get pods                        # 查看资源对象,查看所有Pod列表
kubectl get rc,service                  # 查看资源对象,查看rc和service列表
kubectl get pod,svc,ep --show-labels    # 查看pod,svc,ep能及标签信息
kubectl get all --all-namespaces        # 查看所有的命名空间
kubectl cluster-info

# 查看资源对象
Kubectl  get  nodes -o wide                       查看节点
kubectl  get  pods -n <namespace> -o wide         查看pod
kubectl  get  svc -n <namespace> -o wide          查看service
kubectl  get  ingress -n <namespace> -o wide      查看ingress
kubectl  get  deploy -n <namespace> -o wide       查看deployment
kubectl  get  ds -n <namespace> -o wide           查看daemonsets
kubectl  get  statefulsets -n <namespace> -o wide 查看statefulsets
kubectl  get  pv                                  查看pv
kubectl  get  pvc  -n <namespace> -o wide         查看pvc
kubectl  get  cm -n <namespace> -o wide           查看configmap
kubectl  get  job -n <namespace> -o wide          查看job
kubectl  get  cronjobs -n <namespace> -o wide     查看cronjob

描述资源对象

kubectl  describe  node <node-name>
kubectl  describe  pod <pod-name> -n <namespace> 
kubectl  describe  svc <svc-name> -n <namespace> 
kubectl  describe  ingress <ingress-name> -n <namespace>
kubectl  describe  deployments <deployments-name> -n <namespace>
kubectl  describe  ds <ds-name> -n <namespace> -o yaml 
kubectl  describe  statefulsets <statefulsets-name> -n <namespace>
kubectl  describe  pv <pv-name> -n <namespace>
kubectl  describe  pvc <pvc-name> -n <namespace>
kubectl  describe  cm <configmap-name> -n <namespace>
kubectl  describe  job <job-name> -n <namespace>
kubectl  describe  cronjob <cronjob-name> -n <namespace>

查看pod日志

kubectl  logs  <pod-name>  -n <namespace> 查看当前pod中日志
kubectl  logs  <pod-name>  -n <namespace> -c <container-name>  查看当前pod中指定容器日志
kubectl  logs  -f <pod-name>  -n <namespace> -c <container-name>  追踪当前pod中容器日志
kubectl  logs  -p <pod-name>  -n <namespace> -c <container-name> 查看上一次重启的容器日志

# 查看标签
kubectl  get  pods -n <namespace>  --show-labels   查看pod的所有标签
kubectl  get  pods -n <namespace> -l key   只查看有这个key的pod
kubectl  get  pods -n <namespace> -L key   查看key对应的value

# 污点标签
kubectl taint node node1 node-role.kubernetes.io/master="":NoSchedule    设置node01不可调度
kubectl taint node node1 node-role.kubernetes.io/master-
posted @ 2021-05-15 09:11  AlexG  阅读(111)  评论(0编辑  收藏  举报