12-Overview-Recommended Labels

concepts/overview/working-with-objects/common-labels/

Recommended Labels 推荐标签

您可以使用比kubectl和仪表板更多的工具来可视化和管理kubernetes对象。一组通用的标签允许工具互操作,以所有工具都能理解的通用方式描述对象。
除了支持工具之外,推荐的标签还以可查询的方式描述应用程序。

元数据是围绕应用程序的概念组织的。kubernetes不是一个平台即服务(platform as-as-a-service,paas),也没有或没有强制执行应用程序的正式概念。相反,应用程序是非正式的,用元数据来描述。应用程序所包含内容的定义是松散的。

Note: These are recommended labels. They make it easier to manage applications but aren’t required for any core tooling.

共享标签和批注共享一个公共前缀:“app.kubernetes.io”。没有前缀的标签是用户专用的。共享前缀确保共享标签不会干扰自定义用户标签。

Labels

为了充分利用这些标签,应该在每个资源对象上应用它们。

Key Description Example Type
app.kubernetes.io/name The name of the application mysql string
app.kubernetes.io/instance A unique name identifying the instance of an application wordpress-abcxzy string
app.kubernetes.io/version The current version of the application (e.g., a semantic version, revision hash, etc.) 5.7.21 string
app.kubernetes.io/component The component within the architecture database string
app.kubernetes.io/part-of The name of a higher level application this one is part of wordpress string
app.kubernetes.io/managed-by The tool being used to manage the operation of an application helm string

To illustrate these labels in action, consider the following StatefulSet object:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: wordpress-abcxzy
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
    app.kubernetes.io/managed-by: helm

Applications And Instances Of Applications

An application can be installed one or more times into a Kubernetes cluster and, in some cases, the same namespace. For example, wordpress can be installed more than once where different websites are different installations of wordpress.应用程序可以安装到kubernetes集群中一次或多次,在某些情况下,也可以安装到同一命名空间中。例如,WordPress可以在不同网站安装WordPress时多次安装。

The name of an application and the instance name are recorded separately. For example, WordPress has a app.kubernetes.io/name of wordpress while it has an instance name, represented as app.kubernetes.io/instance with a value of wordpress-abcxzy. This enables the application and instance of the application to be identifiable. Every instance of an application must have a unique name.应用程序名和实例名分别记录。例如,wordpress的“app.kubernetes.io/name”为“wordpress”,而实例名为“app.kubernetes.io/instance”,值为“wordpress abcxzy”。这使得应用程序和应用程序实例可以识别。应用程序的每个实例都必须具有唯一的名称。

Examples

To illustrate different ways to use these labels the following examples have varying complexity.为了说明使用这些标签的不同方法,下面的示例具有不同的复杂性。

A Simple Stateless Service

考虑使用 Deployment and Service objects. 下面的两个片段代表了如何以最简单的形式使用标签。

The Deployment 用于监视运行应用程序本身的pod.

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxzy
...

The Service is used to expose the application.

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: myservice
    app.kubernetes.io/instance: myservice-abcxzy
...

Web Application With A Database

考虑一个稍微复杂一点的应用程序:使用数据库(mysql)的web应用程序(wordpress),使用helm安装。下面的代码片段演示了用于部署此应用程序的对象的开始。

The start to the following Deployment is used for WordPress:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: wordpress
    app.kubernetes.io/instance: wordpress-abcxzy
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

The Service is used to expose WordPress:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: wordpress
    app.kubernetes.io/instance: wordpress-abcxzy
    app.kubernetes.io/version: "4.9.4"
    app.kubernetes.io/managed-by: helm
    app.kubernetes.io/component: server
    app.kubernetes.io/part-of: wordpress
...

MySQL is exposed as a StatefulSet以及它所属的更大的应用程序的元数据:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxzy
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

The Service is used to expose MySQL as part of WordPress:

apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql-abcxzy
    app.kubernetes.io/version: "5.7.21"
    app.kubernetes.io/managed-by: helm
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: wordpress
...

With the MySQL StatefulSet and Service you’ll notice information about both MySQL and Wordpress, the broader application, are included.使用mysql的statefulset和service,您会注意到mysql和wordpress这两个更广泛的应用程序的相关信息。

k8s
本作品采用《CC 协议》,转载必须注明作者和本文链接
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!