How to Deploy Apps with Kubernetes: A Step-by-Step Beginner’s Guide

How to Deploy Apps with Kubernetes: A Step-by-Step Beginner’s Guide

Deploying applications with Kubernetes can seem intimidating at first but once you understand the workflow, it becomes one of the most powerful tools in modern DevOps. This guide walks you through the full process of deploying an app step by step, using clear explanations and practical examples.

What is Kubernetes (and Why Use It)?

Kubernetes is an open-source platform designed to automate deploying, scaling, and managing containerized applications.

Instead of manually handling servers, Kubernetes:

  • Schedules containers automatically
  • Restarts failed applications
  • Scales apps up/down based on demand
  • Manages networking and load balancing

If you’re already using Docker, Kubernetes is the next logical step for managing containers at scale.

Prerequisites

Before starting, make sure you have:

For beginners, you can use:

  • Minikube (runs locally)
  • Kind

Step 1: Create a Simple Application

Let’s start with a basic app. For example, a simple Node.js server:

// app.js const http = require(‘http’);const server = http.createServer((req, res) => { res.end(‘Hello from Kubernetes!’); });server.listen(3000, () => { console.log(‘Server running on port 3000’); });

Create a package.json and install dependencies if needed.

Step 2: Containerize the Application

Now, package your app using Docker.

Create a Dockerfile:

FROM node:18 WORKDIR /app COPY . . RUN npm install CMD [“node”, “app.js”] EXPOSE 3000

Build and run the image:

docker build -t my-k8s-app . docker run -p 3000:3000 my-k8s-app

Test it locally in your browser:
👉 http://localhost:3000

Step 3: Set Up Kubernetes Cluster

Start your cluster using Minikube:

minikube start

Verify cluster status:

kubectl get nodes

You should see one running node.

Step 4: Create a Deployment

A Deployment defines how your app runs in Kubernetes.

Create deployment.yaml:

apiVersion: apps/v1 kind: Deployment metadata: name: my-app spec: replicas: 2 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: – name: my-app image: my-k8s-app ports: – containerPort: 3000

Apply it:

kubectl apply -f deployment.yaml

Check pods:

kubectl get pods

Step 5: Expose the Application (Service)

Pods are not directly accessible, so we create a Service.

Create service.yaml:

apiVersion: v1 kind: Service metadata: name: my-service spec: type: NodePort selector: app: my-app ports: – port: 80 targetPort: 3000 nodePort: 30007

Apply it:

kubectl apply -f service.yaml

Access your app:

minikube service my-service

Step 6: Scale Your Application

One of Kubernetes’ biggest advantages is scaling.

Scale to 5 replicas:

kubectl scale deployment my-app –replicas=5

Verify:

kubectl get pods

Step 7: Update Your Application

Make a change in your code (e.g., update the message), rebuild the image:

docker build -t my-k8s-app:v2 .

Update deployment:

kubectl set image deployment/my-app my-app=my-k8s-app:v2

Check rollout:

kubectl rollout status deployment/my-app

Step 8: Monitor and Debug

Useful commands:

kubectl get pods kubectl describe pod kubectl logs

For dashboards, enable:

minikube dashboard

Key Kubernetes Concepts Explained

  • Pod: Smallest unit, runs containers
  • Deployment: Manages pods and replicas
  • Service: Exposes your app
  • Node: Machine running your app
  • Cluster: Group of nodes

Common Beginner Mistakes

  • Forgetting to expose ports
  • Using wrong image names
  • Not checking logs when debugging
  • Skipping YAML indentation rules

Best Practices

  • Use versioned images (v1, v2)
  • Keep deployments declarative
  • Monitor resource usage
  • Use namespaces for organization

Real-World Use Case

Imagine deploying an e-commerce app:

  • Frontend + backend run as separate deployments
  • Auto-scaling handles traffic spikes
  • Rolling updates ensure zero downtime

That’s the real power of Kubernetes.

Conclusion

Deploying apps with Kubernetes may feel complex at first, but the workflow is straightforward:

  1. Build your app
  2. Containerize with Docker
  3. Create deployment
  4. Expose via service
  5. Scale and update

Once you practice these steps, you’ll be able to deploy production-ready applications with confidence.

shamitha
shamitha
Leave Comment
Share This Blog
Recent Posts
Get The Latest Updates

Subscribe To Our Newsletter

No spam, notifications only about our New Course updates.

Enroll Now
Enroll Now
Enquire Now