我如何列出我的GKE集群中的工作负载?

huangapple go评论67阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年6月13日 00:43:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76458704.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定