k8 - kubectl常用命令

前置技能,熟练掌握 docker 相关命令,有很多与 docker 类似的命令

作为运维人员,基本要求背诵的命令

# 获取 default 命名空间下的 pod
kubectl get pods
# 获取指定命名空间下的 pod
kubectl get pods -n [namespace]
# 获取所有 pod
kubectl get pods -A
# 获取 yaml 格式的配置信息
kubectl get pod [name] -o yaml

# 获取 default 命名空间下的 pod 的详细信息
kubectl get pods -o wide
# 获取指定命名空间下的 pod 的详细信息
kubectl get pods -n [namespace] -o wide
# 获取所有 pod 的详细信息
kubectl get pods -A -o wide

# get 命令不止用于查看 pod,可以查看一切资源列表,命令格式基本一致

# 获取所有命名空间
kubectl get namespace
# 获取所有节点
kubectl get nodes
# 查看 master 组件状态
kubectl get cs

# 一些经常要查看的资源
# 
# node/no 				集群节点
# deployment/deploy 	无状态服务
# statefulsets/sts 		有状态服务
# replicaset/rs			副本集
# service/svc 			服务
# namespace/ns			命名空间
# pod/po				pod


# 获取 pod 的描述信息
kubectl describe pod [pod-name]
# 获取节点的描述信息
kubectl describe node [node-name]	

# 删除一个 pod,因为有重启策略在,因此通常用于重启
kubectl delete pod [pod-name] -n [namespace]

# delete、describe 等命令,也可用于大部分资源,命令格式基本一致

# 查看日志
kubectl logs [pod-name] -n [namespace]
# 查看日志并持续跟踪
kubectl logs -f [pod-name] -n [namespace]
# 查看尾部 n 行日志
kubectl logs tail [n] [pod-name] -n [namespace]
# 查看末尾100行,并持续跟踪 es 的日志
kubectl logs -f --tail=100 es
# 查看最近6小时,并持续跟踪 es 的日志
kubectl logs -f --since=6h es


# 进入容器,命令与 docker 完全一致
kubectl exec -it [pod-name] bash


# 查看版本
kubectl version

posted on 2016-12-08 21:25  疯狂的妞妞  阅读(262)  评论(0)    收藏  举报

导航