{"id":69,"date":"2022-01-27T05:37:27","date_gmt":"2022-01-27T05:37:27","guid":{"rendered":"https:\/\/blog.kevinyohe.dev\/?p=69"},"modified":"2022-01-27T05:42:53","modified_gmt":"2022-01-27T05:42:53","slug":"kubernetes-labels","status":"publish","type":"post","link":"https:\/\/blog.kevinyohe.dev\/?p=69","title":{"rendered":"Kubernetes Labels"},"content":{"rendered":"<div class=\"wp-block-syntaxhighlighter-code alignwide\"><pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\n# Write the manifest file\ncat &lt;&lt; 'EOF' &gt; pod-labels.yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: red-frontend\n  namespace: labels # ceclare namespace in metadata \n  labels: # labels mapping in metadata\n    color: red\n    tier: frontend\n  annotations: # Example annotation\n    Lab: Kubernetes Pod Design for Application Developers\nspec:\n  containers:\n  - image: httpd:2.4.38\n    name: web-server\n---\napiVersion: v1\nkind: Pod\nmetadata:\n  name: green-frontend\n  namespace: labels\n  labels:\n    color: green\n    tier: frontend\nspec:\n  containers:\n  - image: httpd:2.4.38\n    name: web-server\n---\napiVersion: v1\nkind: Pod\nmetadata:\n  name: red-backend\n  namespace: labels\n  labels:\n    color: red\n    tier: backend\nspec:\n  containers:\n  - image: postgres:11.2-alpine\n    name: db\n---\napiVersion: v1\nkind: Pod\nmetadata:\n  name: blue-backend\n  namespace: labels\n  labels:\n    color: blue\n    tier: backend\nspec:\n  containers:\n  - image: postgres:11.2-alpine\n    name: db\nEOF\n# Create the Pods\nkubectl create -f pod-labels.yaml\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nkubectl get pods -L color,tier\n<\/pre><\/div>\n\n\n<p>Note that multiple resources are separated by&nbsp;<code>---<\/code>&nbsp;in YAML manifest files. Each pod is declared in the&nbsp;<code>labels<\/code>&nbsp;<code>namespace<\/code>.&nbsp;Each Pod also has a&nbsp;<code>labels<\/code>&nbsp;mapping&nbsp;that declares a&nbsp;<code>color<\/code>&nbsp;and a&nbsp;<code>tier<\/code>&nbsp;label. Values for the&nbsp;<code>color<\/code>&nbsp;label span&nbsp;<code>red<\/code>,&nbsp;<code>green<\/code>, and&nbsp;<code>blue<\/code>. Values for the&nbsp;<code>tier<\/code>&nbsp;label span&nbsp;<code>frontend<\/code>&nbsp;and&nbsp;<code>backend<\/code>.&nbsp;The first Pod in the file, named&nbsp;<code>red-frontend<\/code>, also declares an&nbsp;<code>annotations<\/code>&nbsp;mapping.<\/p>\n\n\n\n<p>Use the\u00a0<code>-L<\/code>\u00a0(or\u00a0<code>--label-columns<\/code>)\u00a0<code>kubectl get<\/code>\u00a0option to display columns for both labels:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Note that multiple resources are separated by&nbsp;&#8212;&nbsp;in YAML manifest files. Each pod is declared in the&nbsp;labels&nbsp;namespace.&nbsp;Each Pod also has a&nbsp;labels&nbsp;mapping&nbsp;that declares a&nbsp;color&nbsp;and a&nbsp;tier&nbsp;label. Values for the&nbsp;color&nbsp;label span&nbsp;red,&nbsp;green, and&nbsp;blue. Values for the&nbsp;tier&nbsp;label span&nbsp;frontend&nbsp;and&nbsp;backend.&nbsp;The first Pod in the file, named&nbsp;red-frontend, also declares an&nbsp;annotations&nbsp;mapping. Use the\u00a0-L\u00a0(or\u00a0&#8211;label-columns)\u00a0kubectl get\u00a0option to display columns for both labels:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-uncategorized","entry"],"_links":{"self":[{"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=69"}],"version-history":[{"count":3,"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":73,"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=\/wp\/v2\/posts\/69\/revisions\/73"}],"wp:attachment":[{"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.kevinyohe.dev\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}