kubectl常用命令汇总

 

#查看k8s的所有node节点

kubectl get node

 

#查看ns的pod

kubectl get pod --all-namespaces -o wide

kubectl get pod -n kube-system

 

# 显示 Node 的详细信息

kubectl describe node pnode-5

 

# 显示 Pod 的详细信息, 特别是查看 pod 无法创建的时候的日志

kubectl describe pod <pod-name> -n <ns-name>

 

# 查看 RC 和 service 列表, -o wide 查看详细信息

kubectl get rc,svc

kubectl get pod,svc -o wide 

 

#查看pod的yaml文件

kubectl get pod <pod-name> -n <ns-name> -o yaml

 

#查看pod的日志

kubectl logs <pod-name> -n <ns-name>

kubectl logs -f <pod-name> -n <ns-name>

 

# 根据 yaml 创建资源, apply 可以重复执行,create 不行

kubectl create -f pod.yaml

kubectl apply -f pod.yaml

 

# 基于 pod.yaml 定义的名称删除 pod

kubectl delete -f pod.yaml

 

# 删除所有包含某个 label 的pod 和 service

kubectl delete pod,svc -l name=<label-name>

 

# 查看 endpoint 列表

kubectl get endpoints

 

# 通过bash获得 pod 中某个容器的TTY,相当于登录容器

kubectl exec -it <pod-name> -n <ns-name> bash

 

#编辑pod的yaml文件

kubectl get deployment -n <ns-name>

kubectl edit depolyment <pod-name> -n <ns-name> -o yaml

 

原文地址:https://www.cnblogs.com/chenli90/p/10311655.html