英文:
How can I list workloads in my GKE cluster?
问题
我在我的项目中有一个GKE集群,里面有多个工作负载。
如何在不使用GCP控制台GUI的情况下列出所有工作负载或搜索特定工作负载?
我的目标很简单:以编程的方式(api/sdk/gcloud)查找集群中是否存在名为xpto
的工作负载。
我需要避免使用kubectl命令,而是采用更高级的方法。
英文:
I have a GKE cluster in my project with several workloads.
How can I list all or search for a specific workload without using the GCP console GUI?
My goal is simple: a programmatical way (api/sdk/gcloud) to find if a workload called xpto
exists in the cluster or not.
I need to avoid kubectl commands and rather a high level approach.
答案1
得分: 1
Google Cloud Console 中显示的有关工作负载、服务等数据是从 Kubernetes API 获取的,因此可以通过进行适当的 Kubernetes API 调用(如列举工作负载)来收集相同的数据。您可以参考这些 Kubernetes API 链接 1 2。
由于 Google Kubernetes Engine API 和 gcloud CLI 主要用于配置您的 Google Cloud 集群,因此可能包括以下任务:
- 创建集群。
- 删除集群。
- 配置集群级网络,如旋转集群控制平面 IP 或启用网络策略执行。
- 更新集群上运行的 Kubernetes 版本。
- 添加、删除或修改集群中的节点池。
- 设置用于集群节点的机器类型或节点映像。
- 配置集群运行的地理区域或地区。
英文:
The data about Workloads, Services, etc. that is displayed in the Google Cloud Console is taken from the Kubernetes API, so it might be able to gather the same by making the appropriate Kubernetes API calls such as Enumerate workloads. You can refer to these Kubernetes API links 1 2
As the Google Kubernetes Engine API and gcloud CLI is primarily for configuring your cluster on Google Cloud. This might include tasks such as:
-
Creating a cluster.
-
Deleting a cluster.
-
Configuring cluster-level networking, such as rotating the cluster control plane IP or enabling network policy enforcement.
-
Updating the version of Kubernetes running on the cluster.
-
Adding, removing, or modifying node pools in your cluster.
-
Setting the machine type or node image used for your cluster's nodes.
-
Configuring the geographic zones or regions in which your cluster runs.
答案2
得分: 0
gcloud
更多地用于管理集群基础架构,而不是管理其内部操作,考虑到最终GKE只是另一种K8s实现,而有工具可以管理它。
说到这一点,gcloud
不提供您所要求的功能,因为这就像重新发明轮子,因为kubectl
已经可以做到这一点。实际上,GCP文档不提供使用gcloud container clusters
列出工作负载的方法。
您将检查“工作负载”是否存在的方式将取决于其类型:pod、deployment等,并使用kubectl
。
英文:
gcloud
is more intended to manage the Cluster Infraestructure rather than managing operations inside it considering that at the end GKE it's another K8s implementation and there are tools to manage that.
Said that, gcloud
doesn't offer what you ask because it would be like re-inventing the wheel since kubectl
already does this. In fact the GCP docs don't show a way to list workloads using gcloud container clusters
The way you will check if a "workload" exists will depend on the type of it: a pod, deployment, etc. and using kubectl
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论