Labels - neerajk555/Kubernetes GitHub Wiki
- Create a pod with labels
# pod-with-labels.yaml
apiVersion: v1
kind: Pod
metadata:
name: labeled-pod
labels:
app: myweb
env: staging
spec:
containers:
- name: web
image: nginx
RUN: kubectl apply -f pod-with-labels.yaml
- View the pod and its labels
kubectl get pods --show-labels
- Select the pod using a label selector
kubectl get pods -l app=myweb
You can also combine:
kubectl get pods -l 'app=myweb,env=staging'
- Add a label to an existing pod
kubectl label pod labeled-pod version=v1
- Remove a label
kubectl label pod labeled-pod version-