|NO.Z.00020|——————————|^^ 标准 ^^|——|KuberNetes&标准.V19|——|常用操作.V05|Pod操作|Node操作|

一、pod常用操作
### --- pod常用操作

~~~     # 获取 pod 日志(标准输出)
[root@k8s-master01 ~]#  kubectl logs my-pod             
 
~~~     # 获取含 name=myLabel 标签的 Pods 的日志(标准输出)
[root@k8s-master01 ~]#  kubectl logs -l name=myLabel   
~~~     # 获取上个容器实例的 pod 日志(标准输出)
[root@k8s-master01 ~]#  kubectl logs my-pod --previous  
 
~~~     # 获取 Pod 容器的日志(标准输出, 多容器场景)
[root@k8s-master01 ~]#  kubectl logs my-pod -c my-container  
~~~     # 获取含 name=myLabel 标签的 Pod 容器日志(标准输出, 多容器场景)
[root@k8s-master01 ~]#  kubectl logs -l name=myLabel -c my-container 
 
~~~     # 获取 Pod 中某容器的上个实例的日志(标准输出, 多容器场景)
[root@k8s-master01 ~]#  kubectl logs my-pod -c my-container --previous  
~~~     # 流式输出 Pod 的日志(标准输出)
[root@k8s-master01 ~]#  kubectl logs -f my-pod            
 
~~~     # 流式输出 Pod 容器的日志(标准输出, 多容器场景)
[root@k8s-master01 ~]#  kubectl logs -f my-pod -c my-container   
~~~     # 流式输出含 name=myLabel 标签的 Pod 的所有日志(标准输出)
[root@k8s-master01 ~]#  kubectl logs -f -l name=myLabel --all-containers   
 
~~~     # 以交互式 Shell 运行 Pod
[root@k8s-master01 ~]#  kubectl run -i --tty busybox --image=busybox -- sh 
~~~     # 在指定名字空间中运行 nginx Pod
[root@k8s-master01 ~]#  kubectl run nginx --image=nginx -n mynamespace   
 
~~~     # 运行 ngins Pod 并将其规约写入到名为 pod.yaml 的文件
[root@k8s-master01 ~]#  kubectl run nginx --image=nginx                   
  --dry-run=client -o yaml > pod.yaml
### --- 挂载到一个运行的容器中

[root@k8s-master01 ~]#  kubectl attach my-pod -i   
~~~     # 在本地计算机上侦听端口 5000 并转发到 my-pod 上的端口 6000
[root@k8s-master01 ~]#  kubectl port-forward my-pod 5000:6000  

~~~     # 在已有的 Pod 中运行命令(单容器场景)
[root@k8s-master01 ~]#  kubectl exec my-pod -- ls /   
~~~     # 在已有的 Pod 中运行命令(多容器场景)
[root@k8s-master01 ~]#  kubectl exec my-pod -c my-container -- ls / 
 
~~~     # 显示给定 Pod 和其中容器的监控数据
[root@k8s-master01 ~]#  kubectl top pod POD_NAME --containers               

二、node操作
### --- 节点操作
~~~     # 标记 my-node 节点为不可调度

[root@k8s-master01 ~]#  kubectl cordon my-node   
~~~     # 对 my-node 节点进行清空操作,为节点维护做准备
[root@k8s-master01 ~]#  kubectl drain my-node     
 
~~~     # 标记 my-node 节点为可以调度
[root@k8s-master01 ~]#  kubectl uncordon my-node 
~~~     # 显示给定节点的度量值
[root@k8s-master01 ~]#  kubectl top node my-node  
 
~~~     # 显示主控节点和服务的地址
[root@k8s-master01 ~]#  kubectl cluster-info   
~~~     # 将当前集群状态转储到标准输出
[root@k8s-master01 ~]#  kubectl cluster-info dump    
 
~~~     # 将当前集群状态输出到 /path/to/cluster-state
[root@k8s-master01 ~]#  kubectl cluster-info dump --output-directory=/path/to/cluster-state   
~~~     # 如果已存在具有指定键和效果的污点,则替换其值为指定值

[root@k8s-master01 ~]#  kubectl taint nodes foo dedicated=special-user:NoSchedule

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on 2022-03-29 13:12  yanqi_vip  阅读(31)  评论(0)    收藏  举报

导航