Creating Kubernetes Deployments and Services
CREATED: 2026 / 12 / 04 Fri
UPDATED: 2026 / 12 / 04 Fri
Starting Pods on Kubernetes Cluster Nodes
I will skip how to build the cluster and set up the nodes.
I use Lima on macOS to run the control plane and data plane nodes (Ubuntu 26.04).
# Create a Deployment
$ kubectl create deployment web --image=nginx --replicas=3
# Create a Service
$ kubectl expose deployment web --port=80
Creating Pods on a node means creating a Kubernetes Deployment.
A Deployment is the component responsible for configuring and starting Pods.
You create one, it holds the Pod configuration, and Pods are started according to it.
A Deployment also includes something called a ReplicaSet.
A ReplicaSet is a managed set for each version.
Every time you update a Deployment, a new ReplicaSet is created.
A ReplicaSet holds information about the Pods that should be running, and ReplicaSets are kept up to a specified limit (configurable with the revisionHistoryLimit field under spec in deployment.yaml). Thanks to this, if something goes wrong when you update a Deployment, you can quickly roll back to the version before the update.
Note that ReplicaSets accumulate per Deployment, so deleting a Deployment deletes all of its ReplicaSets.
About Services
Once you create a Deployment, Pods start running, but they only run in a closed way inside the node.
A typical application receives external requests through a reverse proxy such as Nginx, but just creating a Deployment does not make it work that way.
What you need for that is the Service creation command shown in the snippet above.
A Service is something like an interface that defines the network entry and exit point for Pods.
It is a logical group that bundles one or more Pods (that is, the Pods grouped by a Deployment) and provides a single interface for them.
flowchart TB
Service
subgraph Pod
ContainerA
ContainerB
end
Service --> ContainerA
Service --> ContainerB
ContainerA --> Service
ContainerB --> Service
kubectl expose deployment web --port=80 creates an interface (a Service) that makes the Pods of the Deployment named web accessible on port 80.
The Service is assigned an IP address on the cluster.
Using it, Services can talk to each other, and the Pods can be reached from outside.
Pods are also assigned IP addresses.
The reason to use a Service anyway is that a Pod’s IP address changes when, for example, the Pod restarts.
If the IP address changes, something that connected at first can stop connecting later.
A Service provides a fixed entry point, so even if the Pods behind it are recreated, you can still reach them at a fixed IP address.
Also, creating a Service alone does not make it accessible from outside the cluster.
A Service only creates an interface usable inside the cluster, so to communicate with the outside you need to create a separate path for access from outside the cluster.
Ways to reach Nginx and the like inside the cluster from outside include using port-forward and using Ingress (there are others as well).
Here I only cover the port-forward approach.
port-forward is a way to make a Service accessible from localhost on the node running kubectl, using kubectl port-forward.
$ kubectl create deployment web --image=nginx --replicas=3
$ kubectl expose deployment web --port=80
# Make port 80 of the Service web in the cluster accessible at localhost:8080
$ kubectl port-forward service/web 8080:80
In this state, you can view the Nginx page from a browser on the node running kubectl.
Since this assumes Lima on macOS, the Lima Ubuntu VM is the node running kubectl, but Lima kindly makes it accessible from localhost on macOS as well (by default it forwards ports to the host automatically).
About Pods
Starting Pods and configuring Services work as described above.
On top of that, let me also sort out how a Pod is structured.
If you have used Docker or Docker Compose, you may tend to map a Deployment’s structure to something like the setup defined in docker-compose.yaml.
I did too, but with that assumption, Pods become hard to understand.
A Pod is strictly a unit that manages a group of containers with the same configuration, and you normally do not put Nginx, an API server, and a DB together in one.
A Pod contains multiple container groups, as many as specified by replicas, and each container group runs containers of different kinds.
You could include Nginx, an API server, and a DB there, but as a Pod design it is more common to run multiple Nginx-only containers in a Pod and bundle that setup, designed for Nginx availability and fault tolerance, as one Pod.
That said, running tools for sending logs and metrics, or other security tools, as sidecars of that Nginx container does happen.
In other words, the picture is that the reverse proxy, the API server, and the DB each start as separate Pods, each with its own replicas, so each can scale out and in independently.
flowchart LR
subgraph Node
Service-web
Service-api
Service-db
subgraph Pod-A[Nginx]
Nginx-A
Nginx-B
end
subgraph Pod-B[API]
API-A
API-B
end
subgraph Pod-C[DB]
DB-A
DB-B
end
end
Service-web --> Nginx-A
Service-web --> Nginx-B
Nginx-A --> Service-api
Nginx-B --> Service-api
Service-api --> API-A
Service-api --> API-B
API-A --> Service-db
API-B --> Service-db
Service-db --> DB-A
Service-db --> DB-B
Appendix
kubectl command cheat sheet
# Deployment
$ kubectl get deployment -A # List
$ kubectl create deployment web --image=nginx --replicas=3 # Create
# Service
$ kubectl get service -A # List
$ kubectl expose deployment web --port=80 # Create
# Pod
$ kubectl get pods -A -o wide # List
# Node
$ kubectl get nodes -o wide # List
$ kubectl describe node $NODE_NAME # Details
$ kubectl delete node $NODE_NAME # Delete
$ kubectl describe node $NODE_NAME | grep Taints # Check Taint status
# Taint
$ kubectl taint nodes $NODE_NAME key=value:NoSchedule # Add a Taint to a Node
$ kubectl taint nodes $NODE_NAME key=value:NoSchedule- # Remove a Taint from a Node
# Namespace
$ kubectl get namespaces # List
$ kubectl create namespace team-a # Create
$ kubectl delete namespace team-a # Delete