kubectl系列(五)-kubectl get

本文详细介绍了kubectlget命令用于获取Kubernetes的各种资源,如nodes、pods、namespaces等,以及其可选参数、使用案例,包括查看资源列表、格式化输出、过滤和命名空间管理等。
摘要由CSDN通过智能技术生成

kubectl get 命令可以获取所有的resources,包括node、pod 、namespace、service 、deployment等等。

1 命令格式

kubectl get resource名称

2 resource列表 

  • all
  • certificatesigningrequests,简写csr
  • clusterrolebindings
  • clusterrol
  • componentstatuses,简写cs
  • configmaps,简写cm
  • controllerrevisions
  • cronjobs
  • customresourcedefinition,简写crd
  • daemonsets,简写ds
  • deployments,简写deploy
  • endpoints,简写ep
  • events,简写ev
  • horizontalpodautoscalers,简写hpa
  • ingresses,简写ing
  • jobs
  • limitranges,简写limits
  • namespaces,简写ns
  • networkpolicies,简写netpol
  • nodes,简写no
  • persistentvolumeclaims,简写pvc
  • persistentvolumes,简写pv
  • poddisruptionbudgets,简写pdb
  • podpreset
  • pods 简写po
  • podsecuritypolicies,简写psp
  • podtemplates
  • replicasets,简写rs
  • replicationcontrollers,简写rc
  • resourcequotas,简写quota
  • rolebindings
  • roles
  • secrets
  • serviceaccounts,简写sa
  • services,简写svc
  • statefulsets,简写sts
  • storageclasses,简写sc

3 可选参数

  • 用不同的格式查看

-o wide/yaml/json

  • 看指定标签的pods,支持’=’, ‘==’, and ‘!=’操作符

-l key=value

  • 查看指定的命名空间

-n 命名空间

4 案例

4.1 获取所有resources
kubectl api-resources
4.2 列出全局可配置的选项,适用于所有命令
kubectl options
4.3 获取namespace
kubectl get ns
4.4 获取pod

1)某个namespace下的pod

kubectl -n prd get pod

2)获取所有namespace下的pod

kubectl get po -A

3)查看pod运行node信息

kubectl get pod -n nsname -o wide 
#kubectl get pod -n prod  -o wide 
NAME                READY   STATUS    RESTARTS   AGE    IP             NODE                        NOMINATED NODE   READINESS GATES
log-cleaner-5kmvq   1/1     Running   0          169d   172.16.0.163   cn-hangzhou.172.28.10.39    <none>           <none>
log-cleaner-8vqst   1/1     Running   0          169d   172.16.4.178   cn-hangzhou.172.28.10.32    <none>           <none>
log-cleaner-9vg6r   1/1     Running   0          169d   172.16.4.44    cn-hangzhou.172.28.10.30    <none>           <none>
log-cleaner-fdgwl   1/1     Running   0          169d   172.16.2.64    cn-hangzhou.172.28.10.19    <none>           <none>
log-cleaner-kz9v9   1/1     Running   0          169d   172.16.2.245   cn-hangzhou.172.28.132.24   <none>           <none>
log-cleaner-m7sxs   1/1     Running   0          169d   172.16.3.180   cn-hangzhou.172.28.10.31    <none>           <none>
log-cleaner-qk2q7   1/1     Running   0          169d   172.16.0.30    cn-hangzhou.172.28.10.38    <none>           <none>
log-cleaner-r6rgg   1/1     Running   0          169d   172.16.3.27    cn-hangzhou.172.28.10.27    <none>           <none>
4.5 获取指定pod的日志
kubectl -n prd logs -f podName
4.6 进入某个pod中的container
kubectl -n prd exec -it podName sh
4.7 查看某个pod详情
kubectl -n prd describe pods/podName
4.8 查看svc

1)查看指定ns的svc

kubectl get svc -n nsname

2)查看所有ns的svc

kubectl get svc -A

 其他命令可使用--help查询。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

alden_ygq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值