Day 32 : Launching your Kubernetes Cluster with Deployment
DevOps Learning

Before launching application, let's cover some important terms.
What Is a Kubernetes Deployment?
A Deployment is like the conductor of an orchestra—it manages the rollout and updates of your application’s Pods and ReplicaSets.
Declarative Updates:
A Deployment provides declarative updates for your application.
You describe the desired state (how many replicas, which image, etc.) in a Deployment manifest (usually a YAML file).
The Deployment Controller then ensures the actual state matches the desired state.
Use Cases:
Rollout New Versions:
When you want to release a new version of your app, create a new Deployment with updated settings (like a new image version).
Kubernetes gradually replaces old Pods with new ones, ensuring zero downtime.
Rollback:
- If the new version causes issues, you can easily roll back to a previous Deployment revision.
Scaling:
- Need more Pods? Scale up the Deployment.
Pause and Resume:
- Temporarily pause a Deployment to make multiple fixes to its Pod template, then resume to start a new rollout.
Cleanup:
- Deployments also help clean up older ReplicaSets that you no longer need.
Example Deployment YAML:
Here’s a simple example creating a Deployment for todo-app:
apiVersion: apps/v1 kind: Deployment metadata: name: todo-app labels: app: todo spec: replicas: 2 selector: matchLabels: app: todo template: metadata: labels: app: todo spec: containers: - name: todo image: trainwithshubham/django-todo:latest ports: - containerPort: 8000- This Deployment creates three todo-app Pods.
Why Use Deployments?
They abstract away the complexity of managing individual Pods and ReplicaSets.
You focus on the desired state, and Kubernetes handles the rest.
Deploying todo-app
Create deployment for the application. Use example YML file.

These commands are already covered in Day 31.
After running the deployment, your application is still not accessible to the outside world. You can verify this by running the following command.
kubectl get pods -o wide

There is no route to the host because the pods are running on private IPs (ClusterIP). For this we have to create a service.
What Is a Kubernetes Service?
A Service in Kubernetes guides network traffic to the right Pods within your cluster.
Purpose:
A Service provides a stable, network-accessible endpoint for a set of Pods.
It abstracts away the complexity of individual Pod IPs and ensures your application remains reachable even as Pods come and go.
Why Use Services?
Decoupling: Services decouple the frontend (clients) from the backend (Pods). Clients don’t need to know which specific Pods are serving them.
Load Balancing: Services distribute incoming traffic across multiple Pods (load balancing).
Stable DNS Name: Each Service gets a DNS name (e.g.,
my-service.default.svc.cluster.local), making it easy for clients to find it.
Types of Services:
ClusterIP: Default type. Exposes the Service on an internal IP within the cluster.
NodePort: Exposes the Service on a static port on each node’s IP.
LoadBalancer: Creates an external load balancer (cloud provider-specific) and assigns a public IP.
ExternalName: Maps a Service to an external DNS name (no load balancing).
Selectors and Endpoints:
A Service selects Pods based on labels (defined in the Service spec).
The set of Pods targeted by a Service is determined by a selector.
The Service maintains a list of endpoints (Pod IPs) that match the selector.
Example YAML for a Service:
apiVersion: v1 kind: Service metadata: name: todo-app-service spec: type: NodePort selector: app: todo ports: - port: 80 # By default and for convenience, the `targetPort` is set to # the same value as the `port` field. targetPort: 8000 # Optional field # By default and for convenience, the Kubernetes control plane # will allocate a port from a range (default: 30000-32767) nodePort: 30009- This Service exposes Pods labeled with
app: my-appon port 80.
- This Service exposes Pods labeled with
Ingress vs. Service:
Ingress controls external access to your services (HTTP/HTTPS routing).
Service exposes internal services within the cluster.
Create service for the application by using above example YML file.

Get all the available services.
kubectl get svc

To get a external IP.
minikube service todo-app-service


Thank you for reading😉.



