官术网_书友最值得收藏!

Using Kubernetes labels

When you have an application that consists of one pod and one service, there is no problem operating these resources. But when your application grows, or you have tens or hundreds of projects, pods, services and other Kubernetes resources, it will get harder to operate and effectively troubleshoot Kubernetes. This is where we can use the Kubernetes labels we mentioned earlier in this chapter. We are going to run a couple more Kubernetes pods using labels:

$ kubectl run httpd1 --image=httpd --labels="app=httpd-demo1"
$ kubectl run httpd2 --image=httpd --labels="app=httpd-demo2"

Check the Kubernetes pods we have at the moment:

$ kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-8576c89d7-qjd62 1/1 Running 0 17m
httpd1-c9f7d7fd9-rn2nz 1/1 Running 0 21s
httpd2-5b4ff5cf57-9llkn 1/1 Running 0 15s

Now, imagine you have at least 10 or more pods. In order to efficiently filter out this output, we can use the -l option:

$ kubectl get pods -l="app=httpd-demo2"
NAME READY STATUS RESTARTS AGE
httpd2-5b4ff5cf57-9llkn 1/1 Running 0 2m
Filtering out output with Kubernetes labels is not the only use case. Labels are also used alongside selectors. You can get more information on both topics using the Kubernetes official documentation at  https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/.
主站蜘蛛池模板: 灵川县| 利辛县| 福鼎市| 阜宁县| 德保县| 岐山县| 边坝县| 团风县| 长沙县| 孟村| 龙海市| 天等县| 长宁县| 西贡区| 定襄县| 黎城县| 寻甸| 诸暨市| 常山县| 根河市| 五河县| 荃湾区| 东宁县| 通江县| 定西市| 桦甸市| 邓州市| 奉贤区| 陈巴尔虎旗| 璧山县| 双柏县| 江孜县| 武义县| 伽师县| 淳化县| 巴彦淖尔市| 曲麻莱县| 西平县| 普格县| 义马市| 香港 |