kubernetes - 如何使用 cli 获取 kube-contexts 列表
问题描述
我正在尝试获取 kube-contexts 列表(并过滤 gke 集群),并使用一些工具结束了:
kubectl config get-contexts | tr -s ' ' | cut -d ' ' -f 2 | grep gke
输出:
gke_dev-redacted
gke_prod-redacted
有没有更简单的方法来做到这一点(这不取决于命令输出不使用制表符,而是使用多个空格的事实)。该命令不支持 yaml 或 json 输出:
--output yaml is not available in kubectl config get-contexts; resetting to default output format
解决方案
您可以提供--output
标志以仅显示上下文的名称,例如:
$ kubectl config get-contexts --output=name
minikube
然后很容易找到 GKE 上下文:
$ kubectl config get-contexts --output=name | grep "gke_*"
推荐阅读
- c++ - C++20 字符串文字模板参数工作示例
- r - R dplyr 包含多个常量列
- python - 基于时间的数据过滤
- javascript - LeetCode 120:三角形 - 最小路径和
- oracle-apex - 如何为 Oracle APEX Popup LOV 设置值
- flutter - Flutter:Firestore:snapshot().listener 连接何时被切断?
- python - Python中的数据框
- html - 如何在 html 中有一个动态的有序列表?
- erlang - 是什么 | 和 || 在 Erlang 中是什么意思?
- function - 从不推荐使用的 cudnn 函数转换为工作函数