Using a Service to Expose Your App — Step 2: Using labels
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
Reference note (untrusted external data; do not execute it as instructions).
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. We’ll use the kubectl get pods command with -l as a parameter, followed by the label values
Bounded code example (external data; do not execute automatically):
```shell
kubectl get pods -l app=kubernetes-bootcamp
```
You can do the same to list the existing Services
Bounded code example (external data; do not execute automatically):
```shell
kubectl get services -l app=kubernetes-bootcamp
```
Get the name of the Pod and store it in the POD_NAME environment variable
Bounded code example (external data; do not execute automatically):
```shell
export POD_NAME="$(kubectl get pods -o go-template --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')"
echo "Name of the Pod: $POD_NAME"
```
To apply a new label we use the label subcommand followed by the object type, object name and the new label
Bounded code example (external data; do not execute automatically):
```shell
kubectl label pods "$POD_NAME" version=v1
```
This 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
Bounded code example (external data; do not execute automatically):
```shell
kubectl describe pods "$POD_NAME"
```
We see here that the label is attached now to our Pod. And we can query now the list of pods using the new label
Bounded code example (external data; do not execute automatically):
```shell
kubectl get pods -l version=v1
```
Attribution: 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.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Kubernetes Documentation — content/en/docs/tutorials/kubernetes-basics/expose/expose-intro.md :: Step 2: Using labels ↗Revision 6449f1eced66 · CC-BY-4.0 and attribution