kubectl get secret命令用法介绍
kubectl get secret命令用法介绍
kubectl get secret --namespace postgres iot-postgres-postgresql -o jsonpath=,这个命令是用来获取在指定namespace下指定名称的secret的json格式。接下来从多个方面进行详细阐述。
一、命令构成分析
1、kubectl get:表示获取资源
kubectl get
2、secret:表示获取secret资源
kubectl get secret
3、--namespace postgres:表示获取postgres命名空间下的secret资源
kubectl get secret --namespace postgres
4、iot-postgres-postgresql:表示获取名称为iot-postgres-postgresql的secret资源
kubectl get secret --namespace postgres iot-postgres-postgresql
5、-o jsonpath=:表示返回的json格式的内容
kubectl get secret --namespace postgres iot-postgres-postgresql -o jsonpath=
二、命令参数说明
1、-o/--output:指定返回的输出格式(json、yaml、wide等),如果不指定则默认使用表格格式
kubectl get secret --namespace postgres iot-postgres-postgresql -o yaml
2、--show-labels:显示pod的标签信息
kubectl get pod --namespace postgres --show-labels
3、--sort-by:按照指定字段排序输出
kubectl get pod --sort-by=.metadata.creationTimestamp
4、-l/--selector:按照指定标签筛选
kubectl get pod --selector=app=nginx
5、-A/--all-namespaces:获取所有命名空间下的资源
kubectl get pod -A
三、常用技巧
1、获取secret具体某个字段的值
kubectl get secret --namespace postgres iot-postgres-postgresql -o jsonpath='{.data.postgresql-password}' | base64 --decode
2、将多个kubectl命令合并成一条命令
kubectl get pod --namespace postgres; kubectl get deployment --namespace postgres
kubectl get pod,deployment --namespace postgres
四、命令实例
获取postgres命名空间下名称为iot-postgres-postgresql的secret的json格式:
kubectl get secret --namespace postgres iot-postgres-postgresql -o jsonpath=
获取postgres命名空间下名称为iot-postgres-postgresql的secret的postgresql-password字段的值:
kubectl get secret --namespace postgres iot-postgres-postgresql -o jsonpath='{.data.postgresql-password}' | base64 --decode
获取所有namespace下名称为iot-postgres-postgresql的pod:
kubectl get pod --all-namespaces | grep "iot-postgres-postgresql"
评论关闭