Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kubernetes 是否向展开添加一些标签?_Kubernetes_Label - Fatal编程技术网

Kubernetes 是否向展开添加一些标签?

Kubernetes 是否向展开添加一些标签?,kubernetes,label,Kubernetes,Label,我是K8S的初学者,我有一个关于kubernetes标签的问题。在youtube视频上,我看到: 该人员使用这些命令创建三个部署,并运行命令kubectl get deployment,然后kubectl get deployment--show labels: kubectl run monnginx --image nginx --labels "env=prod,group=front" kubectl run monnginx2 --image nginx --lab

我是K8S的初学者,我有一个关于kubernetes标签的问题。在youtube视频上,我看到:

该人员使用这些命令创建三个部署,并运行命令
kubectl get deployment
,然后
kubectl get deployment--show labels

kubectl run monnginx --image nginx --labels "env=prod,group=front"
kubectl run monnginx2 --image nginx --labels "env=dev,group=front"
kubectl run monnginx3 --image nginx --labels "env=prod,group=back"
目前,如果我尝试做同样的事情:

root@kubermaster:~ kubectl run mynginx --image nginx --labels "env=prod,group=front"
pod/mynginx created

root@kubermaster:~ kubectl run mynginx2 --image nginx --labels "env=dev,group=front"
pod/mynginx2 created

root@kubermaster:~ kubectl run mynginx3 --image nginx --labels "env=dev,group=back"
pod/mynginx3 created

当我尝试命令
kubectl get deployments--show labels
时,输出为:

No resources found in default namespace.
NAME       READY   STATUS    RESTARTS   AGE     LABELS
mynginx    1/1     Running   0          2m39s   env=prod,group=front
mynginx2   1/1     Running   0          2m32s   env=dev,group=front
mynginx3   1/1     Running   0          2m25s   env=dev,group=back
但是如果我尝试
kubectl get pods--show labels
,结果是:

No resources found in default namespace.
NAME       READY   STATUS    RESTARTS   AGE     LABELS
mynginx    1/1     Running   0          2m39s   env=prod,group=front
mynginx2   1/1     Running   0          2m32s   env=dev,group=front
mynginx3   1/1     Running   0          2m25s   env=dev,group=back
如果我按照视频中的每个步骤进行操作,有一种方法可以在展开上放置一些标签…但是命令
kubectl create deployment
不接受标志--labels:

Error: unknown flag: --labels
有人来解释我为什么会犯这个错误,以及如何贴上标签


非常感谢!

因为
$kubectl create deployment
不支持
--labels
标志。但是您可以使用
$kubectl label
将标签添加到部署中

示例:

# Update deployment 'my-deployment' with the label 'unhealthy' and the value 'true'.
$ kubectl label deployment my-deployment unhealthy=true
  
# Update deployment 'my-deployment' with the label 'status' and the value 'unhealthy', overwriting any existing value.
$ kubectl label --overwrite deployment my-deployment status=unhealthy
它也适用于其他Kubernetes对象。


格式:
kubectl label[--overwrite](-f FILENAME | TYPE NAME)KEY_1=VAL_1…KEY_N=VAL_N

,因为
$kubectl create deployment
不支持
--labels
标志。但您可以使用
$kubectl label
将标签添加到部署中

示例:

# Update deployment 'my-deployment' with the label 'unhealthy' and the value 'true'.
$ kubectl label deployment my-deployment unhealthy=true
  
# Update deployment 'my-deployment' with the label 'status' and the value 'unhealthy', overwriting any existing value.
$ kubectl label --overwrite deployment my-deployment status=unhealthy
它也适用于其他Kubernetes对象。


格式:
kubectl label[--overwrite](-f FILENAME | TYPE NAME)KEY_1=VAL_1…KEY_N=VAL_N

我认为问题有所不同

在Kubernetes 1.17之前,命令
kubectl run
创建了一个部署。
由于Kubernetes 1.18,命令
kubectl run
创建一个pod

库伯内特斯1.18

kubectl run has removed the previously deprecated generators, along with flags 
unrelated to creating pods. kubectl run now only creates pods. See specific 
kubectl create subcommands to create objects other than pods. (#87077, 
@soltysh) [SIG Architecture, CLI and Testing]

我认为问题是不同的

在Kubernetes 1.17之前,命令
kubectl run
创建了一个部署。
由于Kubernetes 1.18,命令
kubectl run
创建一个pod

库伯内特斯1.18

kubectl run has removed the previously deprecated generators, along with flags 
unrelated to creating pods. kubectl run now only creates pods. See specific 
kubectl create subcommands to create objects other than pods. (#87077, 
@soltysh) [SIG Architecture, CLI and Testing]

您正在运行一个pod并试图获取deplpyment…这是正确的。请注意yout命令的输出:
pod/mynginx created
您创建了一个名为
mynginx
pod
。您可以阅读更多有关您正在运行一个pod并试图获取deplpyment…的差异的信息,这是正确的。请注意yout命令的输出:
pod/mynginx created
您创建了一个名为
mynginx
pod
…您可以阅读更多有关差异的信息