在此k8s yaml中哪些名称应相同 [英] Which names should be same in this k8s yaml

查看:102
本文介绍了在此k8s yaml中哪些名称应相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-app
  labels:
    run: my-app
spec:
  replicas: 3
  selector:
    matchLabels:
      run: my-app
  template:
    metadata:
      labels:
        run: my-app
    spec:
      containers:
      - image: gcr.io/google-samples/hello-app:1.0
        name: my-app
        ports:
        - containerPort: 8080

这是来自kubenetes网站的样本yaml,有很多my-app,它们都必须相同吗?他们的目的是什么?

This is a sample yaml from kubenetes site, there are so many my-app, do they all have to be same? what are their purpose?

推荐答案

这是来自kubenetes网站的示例yaml,有太多my-app,它们都必须相同吗?他们的目的是什么?

This is a sample yaml from kubenetes site, there are so many my-app, do they all have to be same? what are their purpose?

不,在name字段中,它们不必相同,可以不同.在metadataselector部分中看到的my-app引用 是标签,可用于粘贴不同的Kubernetes查询Kubernetes时将对象放在一起,或者只是选择对象的子集.有时它们是相同的.

No they don't have to be the same as far as the name field goes, that can be different. The my-app references seen in the metadata and selector sections are labels that can be used to glue the different Kubernetes objects together or simply select a subset of objects when querying Kubernetes. They will sometimes be the same.

取决于您如何创建展开,您可能在整个展开中以及从其派生的对象中都具有run: myapp.使用kubectl run my-app --image=gcr.io/google-samples/hello-app:1.0 --replicas=3会创建您要引用的相同部署.

Depending on how you've created the Deployment you may have run: myapp throughout the Deployment and in the objects derived from it. Using kubectl run my-app --image=gcr.io/google-samples/hello-app:1.0 --replicas=3 would create a identical Deployment you're referring to.

下面的图片展示了如何使用不同的run: my-app标签,并以上面的Deployment为灵感:

Here's a picture showing how the different run: my-app labels are used, using the Deployment above as an inspiration:

上面的图片为您展示了Deployment(部署)以及如何使用template框(蓝色)创建指定副本(Pods)的数量.从部署"的角度来看,每个Pod的metadata部分中都将带有run: my-app标签,这将被用作选择其负责的Pod的方式.

The picture above shows you the Deployment and how the template box (blue) are used to create the number of specified replicas (Pods). Each Pod will get a run: my-app label in it's metadata section, from the Deployment point of view this will be used as a way of selecting the Pods it's responsible for.

使用kubectl对Pod子集的类似选择将是:

A similar selection of a subset of Pods using kubectl would be:

kubectl get pods -l run=my-app

这将为您提供所有标记为run: my-app的豆荚.

This will give you all Pods labeled run: my-app.

总而言之,当使用例如sql进行查询时,可以使用标签来选择资源的子集. kubectl或通过其他Kubernetes资源进行选择.您可以创建自己的标签,在整个特定部署中它们不必一定相同,但是如果是这样,则可以很容易地查询带有特定标签的任何资源.

To sum up a bit, labels can be used to select a subset of resources when querying using e.g. kubectl or by other Kubernetes resources to do selections. You can create your own labels and they don't necessarily have to be the same throughout your specific Deployment but if they are it would be pretty easy to query for any resource with a specific label.

这篇关于在此k8s yaml中哪些名称应相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆