Deploying a production‑grade web service requires multiple concurrent instances and a controlled upgrade path. Rolling updates let you replace pods incrementally, preserving availability, while the rollback feature restores the previous revision if a new version introduces errors. The pause/resume mechanism lets you stage several changes—such as image upgrades, replica count adjustments, or resource limit modifications—and apply them as a single rollout.
Kubernetes implements these capabilities through the Deployment object, which sits above ReplicaSets in the resource hierarchy.
ReplicaController in Kubernetes Overview The ReplicaController (RC) is a legacy workload API object that maintains a stable set of pod replicas. It continuously monitors the current state and creates or deletes pods to match the desired replica count defined in its spec. RCs are still supported for backward compatibility but are superseded by ReplicaSets and Deployments for most use‑cases. Even if you have single pod you can still use replica controller so that the pod is redeployed if it is crashed.
Kubernetes Hands-On Mini Lab Goal By the end, you’ll know how to:
Create & manage workloads Debug pods Expose services Scale & update apps Work with namespaces & configs Step 0: Setup Start a cluster (example with Minikube) 1 minikube start Verify:
1 2 kubectl cluster-info kubectl get nodes Step 1: Create a Namespace 1 2 kubectl create namespace lab kubectl get namespaces Use it:
1 kubectl config set-context --current --namespace=lab Step 2: Create a Deployment 1 kubectl create deployment nginx --image=nginx Check:
Kubernetes CLI Reference Core Resource Management View Resources
kubectl get – List resources
Basic: kubectl get pods -n default Wide output: kubectl get pods nginxpod -o wide (shows node placement, pod IP) Label selector: kubectl get pods -l app=k8s-web-app Node details: kubectl get pods -o wide reveals the nodes where the pods are running from and ip details for the pods. kubectl describe pod pod-name reveals image used, node details, number of containers deployed, find why a pod launch failed (under events section) and other details Container status: Output like 1/1 or 1/2 indicates running containers / total containers; values like 0/1 signal container failures kubectl describe – Detailed resource inspection
Building a Flask Image for Minikube Write the application 1 2 3 4 5 6 7 8 9 10 11 12 # app.py from flask import Flask import os app = Flask(__name__) @app.route('/') def home(): return f"Running from pod {os.getenv('POD_NAME', 'unknown')}" if __name__ == '__main__': app.run(host='0.0.0.0', port=80) Create the Dockerfile 1 2 3 4 5 6 FROM python:3.9-slim WORKDIR /app COPY app.py . RUN pip install flask EXPOSE 80 CMD ["python", "app.
Kubernetes definition files, commonly referred to as YAML manifests, are the core mechanism for declaring the desired state of your application and its supporting infrastructure within a Kubernetes cluster. They are not scripts or executable code, but rather data files specifying the configuration of Kubernetes objects.
Core Concepts:
Declarative Configuration: Kubernetes operates on a declarative model. You define what you want, not how to achieve it. The Kubernetes control plane continuously works to reconcile the actual state with the desired state defined in these files.
In a kubernetes environmet, a Pod keeps crashing continously. which commands you would run to check the issue? kubectl get pods
kubectl describe pod
kubectl logs pod
What is the right approach to scale an application? Ans: Deploying additional Pods is the right approach. Deploying more containers is not right option because all the containers within the pod use same network and same resources. so when you add more containers, they still use the same resources in the pod.
Minikube creating k8s environment and kubectl managing the environment Understanding Kubernetes, kubectl, and Minikube When learning Kubernetes, one of the first tools you encounter is kubectl. Many beginners assume Kubernetes “runs with kubectl,” but that’s not exactly true.
kubectl is simply a command-line client. It allows you to communicate with a Kubernetes cluster. When you run commands like kubectl get pods or kubectl get deployments you are sending requests to the Kubernetes API server, which then returns information about the cluster’s resources.
Containers and Orchestration Foundations
Understanding Kubernetes requires grasping two concepts:
Containers – isolated execution environments that share the host kernel while packaging an application’s code, runtime, libraries, and dependencies. Orchestration – the automated management of container lifecycles, networking, storage, and scaling across a cluster of hosts. Only after these fundamentals are clear does Kubernetes’ value proposition become meaningful.
Docker as a Container Runtime
Docker popularized containers for developers by providing a high level CLI and image format.
This article details the implementation of a Python and PostgreSQL application within Docker, focusing on three primary methods for managing credentials: hardcoding, environment files, and terminal injection. It concludes with a robust application implementation featuring data persistence and deletion capabilities.
Section 1: Project Foundation The following static files define the application environment and dependencies. These files remain constant regardless of the credential management strategy used.
File Structure:
1 2 3 4 5 6 project/ ├── Dockerfile ├── requirements.