Cloud Native 8 min read

Master Kubernetes Labels, Namespaces, and Services: Essential Tips

This article explains how to use Kubernetes labels, namespaces, and services—covering label creation and selection, namespace management commands, and service concepts—to help practitioners efficiently organize and expose container workloads within a cluster.

Efficient Ops
Efficient Ops
Efficient Ops
Master Kubernetes Labels, Namespaces, and Services: Essential Tips

01 Label

Kubernetes offers many components such as Deployment for gray releases, StatefulSet for ordered deployment of stateful apps, Service for load balancing, Ingress for external exposure, and PV/PVC for persistent storage.

When managing many Pods and nodes, the first feature to use is Labels, which let you distinguish Pods by app or version and enable advanced selection.

PS: If your Pod looks like this, you need to label it.

How to Apply Labels

Kubernetes can label resources and filter them with label selectors.

List labels

<code>kubectl get po --show-labels</code>

Show specific labels

<code>kubectl get po -L label1,label2</code>

Add label to an existing Pod

<code>kubectl label po xxxx xxxx=manual</code>

Add label to a node

<code>kubectl label node gke-kubia-8f56-node-0rrx gpu=true</code>

List nodes by label selector

<code>kubectl get node -l gpu=true</code>

Labels are not unique identifiers and must be manually updated, which can add complexity in large clusters.

02 Namespace

Namespaces are cluster‑level resources suitable for separating teams or projects; the default namespace exists along with system namespaces such as kube-system.

You can view namespaces with:

<code># kubectl get ns
NAME              STATUS   AGE
default           Active   102d
kube-node-lease  Active   102d
kube-public       Active   102d
kube-system       Active   102d
test              Active   61d</code>

Managing Namespace Resources

Creating a namespace only requires a name, e.g.,

kubectl create namespace qa

. Names must consist of letters, numbers, underscores, and hyphens. Deleting a namespace cascades deletion of all contained resources.

<code># Create a new namespace
kubectl create ns test
# Delete a namespace (use with caution)
kubectl delete ns test</code>

Switching namespaces affects subsequent

kubectl get pods

commands unless the

-n

flag is used.

<code># Switch to kube-system namespace
kubectl config set-context --current --namespace=kube-system
# List pods in the current namespace
kubectl get pods</code>

03 Service

A Service abstracts a set of Pods, providing a stable IP and DNS name, load balancing, and external access. Pods alone have transient IPs that are not reachable from outside the cluster.

Service operates at layer‑4 load balancing; for layer‑7 features, Ingress is recommended, though it has its own limitations.

04 Summary

The article emphasizes the importance of Labels, introduces basic Namespace usage, and outlines Service concepts, encouraging deeper practice beyond architectural diagrams.

KubernetesContainer OrchestrationServicesNamespacesLabels
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.