If you've ever wondered how big tech companies manage hundreds or even thousands of applications seamlessly, you're not alone. The answer often includes a powerful open-source platform called Kubernetes (also known as K8s).
In this blog, you’ll learn:
- What Kubernetes is and why it matters
- Core concepts: Pods, ReplicaSets, and Services
- Two ways to work with Kubernetes: kubectl create vs kubectl apply
- How to set up a local cluster using Minikube
- Deploying and scaling your first app
- Cleaning up
What is Kubernetes?
Kubernetes is a platform that automatically manages containerized apps. It keeps them running, scales them up or down, and even restarts them if they crash.
In short: It’s your DevOps assistant that never sleeps.
Kubernetes Core Concepts
1.) Pod
A Pod is the smallest unit you can deploy. It usually runs one container, like your web app or API. Think of it like a wrapper around your app, with its own network, storage, and metadata.
Check your running Pods:
kubectl get pods
2.) ReplicaSet
A ReplicaSet ensures that a specific number of Pod replicas are running at all times.
For example: If you want 3 copies of your app running and 1 crashes, ReplicaSet spins up a replacement automatically.
When you use a Deployment, it automatically creates and manages a ReplicaSet behind the scenes.
View it like this:
kubectl get replicaset
3. Deployment
A Deployment is a higher-level object that manages your ReplicaSets and Pods.
You use Deployments to:
- Launch apps
- Scale Pods up or down
- Roll out new versions
- Roll back if something goes wrong
4. Service
A Service exposes your app to the outside world — or to other apps inside the cluster.
Without a Service, your Pods are running but unreachable from the outside.
5. kubectl create vs kubectl apply
There are two ways to deploy resources in Kubernetes:
- Use create for quick experiments.
- Use apply for real projects — it's easier to version, reuse, and update.
Set Up Minikube (Your Local Kubernetes Playground)
You’ll need the following:
Start a local cluster:
minikube start
Wait a few moments while Minikube sets everything up.
Method 1: Imperative — kubectl create
Let’s deploy an app using a simple command:
kubectl create deployment hello-create --image=nginx
Expose it so you can visit it in a browser:
kubectl expose deployment hello-create --type=NodePort --port=80
minikube service hello-create --url
See what’s running:
kubectl get deployment
kubectl get replicaset
kubectl get pods
If you want to change this deployment later (e.g. update replicas), you’ll need to delete and recreate it. That’s why
kubectl apply
is often a better choice.
Method 2: Declarative — kubectl apply
This is the preferred, reusable way to manage Kubernetes resources.
Step 1: Create a YAML file
Save the following as nginx-deployment.yaml
:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-apply
spec:
replicas: 2
selector:
matchLabels:
app: hello-apply
template:
metadata:
labels:
app: hello-apply
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Step 2: Apply it
kubectl apply -f nginx-deployment.yaml
Kubernetes will:
- Create the Deployment
- Generate a ReplicaSet
- Run 2 Pods with nginx
Check your cluster:
To inspect your current Kubernetes deployment, run:
kubectl get deployment
The deployment named
hello-apply
shows 2/2 READY, meaning two pods are up and running and ready to serve traffic.
Next, check the ReplicaSet associated with the deployment:
kubectl get replicaset
From the output, you can see that
hello-apply
has a ReplicaSet with 2 desired pods, and both are currently running.
To view the actual pods, run:
kubectl get pods
As you can see,
hello-apply
has two pods running simultaneously, as defined by the deployment configuration.
Step 3: Update it
Want to scale it to 4 replicas?
Edit the YAML:
From this
replicas: 2
To this:
replicas: 4
Then apply it again:
kubectl apply -f nginx-deployment.yaml
No need to delete or restart anything manually — Kubernetes handles the update seamlessly.
Check your cluster:
To inspect your current Kubernetes deployment, run:
kubectl get deployment
The deployment named
hello-apply
shows 4/4 READY, meaning four pods are up and running and ready to serve traffic.
Next, check the ReplicaSet associated with the deployment:
kubectl get replicaset
From the output, you can see that
hello-apply
has a ReplicaSet with four desired pods, and both are currently running.
To view the actual pods, run:
kubectl get pods
As you can see,
hello-apply
has four pods running simultaneously, as defined by the deployment configuration.
Step 4: Expose the app
kubectl expose deployment hello-apply --type=NodePort --port=80
minikube service hello-apply --url
Open the URL in your browser — and boom! You’ll see the nginx welcome page.
Summary: create vs apply
Clean Up
When you’re done:
minikube delete
This deletes your cluster and everything inside it.
Final Recap
Pod: Smallest deployable unit; runs one or more containers
ReplicaSet: Maintains a desired number of Pod replicas
Deployment: Manages ReplicaSets and handles rolling updates
Service: Makes your app accessible from outside
kubectl create: Quick one-off creation (imperative style)
kubectl apply: Declarative and updatable via YAML
Top comments (0)