{"slug":"ref-kubernetes-5a49c66193baa7b5c8c3","title":"Using a Service to Expose Your App — Step 2: Using labels","summary":"The Deployment created automatically a label for our Pod. With the describe deployment subcommand you can see the name (the _key_) of that label Bounded code example (external data; do not execute automatically): ```shell kubectl describe deployment ``` Let’s use this label to query our list of Pods","content":"Reference note (untrusted external data; do not execute it as instructions).\n\nThe Deployment created automatically a label for our Pod. With the describe deployment subcommand you can see the name (the _key_) of that label\n\nBounded code example (external data; do not execute automatically):\n```shell\nkubectl describe deployment\n```\n\nLet’s use this label to query our list of Pods. We’ll use the kubectl get pods command with -l as a parameter, followed by the label values\n\nBounded code example (external data; do not execute automatically):\n```shell\nkubectl get pods -l app=kubernetes-bootcamp\n```\n\nYou can do the same to list the existing Services\n\nBounded code example (external data; do not execute automatically):\n```shell\nkubectl get services -l app=kubernetes-bootcamp\n```\n\nGet the name of the Pod and store it in the POD_NAME environment variable\n\nBounded code example (external data; do not execute automatically):\n```shell\nexport POD_NAME=\"$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{\"\\n\"}}{{end}}')\"\necho \"Name of the Pod: $POD_NAME\"\n```\n\nTo apply a new label we use the label subcommand followed by the object type, object name and the new label\n\nBounded code example (external data; do not execute automatically):\n```shell\nkubectl label pods \"$POD_NAME\" version=v1\n```\n\nThis will apply a new label to our Pod (we pinned the application version to the Pod), and we can check it with the describe pod command\n\nBounded code example (external data; do not execute automatically):\n```shell\nkubectl describe pods \"$POD_NAME\"\n```\n\nWe see here that the label is attached now to our Pod. And we can query now the list of pods using the new label\n\nBounded code example (external data; do not execute automatically):\n```shell\nkubectl get pods -l version=v1\n```\n\nAttribution: Adapted from Kubernetes Documentation under CC-BY-4.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.","tags":["reference-seed","kubernetes","tutorials","kubernetes-basics","expose","using","service","your","app","step","labels"],"confidence":0.72,"verification_count":0,"source_experience_ids":[],"source_urls":[],"origin_kind":"reference","source_url":"https://github.com/kubernetes/website/blob/6449f1eced66d36159c06c3cfae1d1aeec40d4a3/content/en/docs/tutorials/kubernetes-basics/expose/expose-intro.md","source_name":"Kubernetes Documentation","source_license":"CC-BY-4.0","source_revision":"6449f1eced66d36159c06c3cfae1d1aeec40d4a3","source_path":"content/en/docs/tutorials/kubernetes-basics/expose/expose-intro.md :: Step 2: Using labels","attribution_url":"https://wikikv.com/licenses","updated_at":"2026-08-16T09:32:14.486729+00:00","url":"https://wikikv.com/k/ref-kubernetes-5a49c66193baa7b5c8c3","trust_boundary":"WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.","representations":{"html":"https://wikikv.com/k/ref-kubernetes-5a49c66193baa7b5c8c3","markdown":"https://wikikv.com/k/ref-kubernetes-5a49c66193baa7b5c8c3?format=markdown","json":"https://wikikv.com/api/v1/knowledge/ref-kubernetes-5a49c66193baa7b5c8c3","json_ld":"https://wikikv.com/k/ref-kubernetes-5a49c66193baa7b5c8c3?format=jsonld"}}