How to Use Kubernetes to Deploy Your First Application.

How to Use Kubernetes to Deploy Your First Application.

Kubernetes has become the go-to platform for deploying and managing containerized applications at scale. But if you’re just starting out, it can feel overwhelming pods, clusters, services, deployments… it’s a lot.

This guide is designed to simplify things. By the end, you’ll understand the core concepts and deploy your first application on Kubernetes step by step.

What is Kubernetes?

Kubernetes (often abbreviated as K8s) is an open-source platform that automates:

  • Deployment of applications
  • Scaling based on demand
  • Management of containerized workloads

Think of it as a system that ensures your app is always running smoothly even if parts of your infrastructure fail.

Prerequisites

Before we begin, make sure you have:

Step 1: Set Up Your Kubernetes Environment

If you’re a beginner, the easiest way to start is by using Minikube, which runs Kubernetes locally.

Install Minikube

brew install minikube # macOS

Or follow official installation instructions for your OS.

Start Minikube

minikube start

Verify installation

kubectl get nodes

You should see a node listed as “Ready”.

Step 2: Create a Simple Application

Let’s deploy a basic application using a Docker container.

Here’s a simple example using an Nginx server.

Step 3: Create a Deployment YAML File

In Kubernetes, we define resources using YAML files.

Create a file called:

deployment.yaml

Add the following content:

apiVersion: apps/v1 kind: Deployment metadata: name: my-first-app spec: replicas: 2 selector: matchLabels: app: my-app template: metadata: labels: app: my-app spec: containers: – name: nginx-container image: nginx:latest ports: – containerPort: 80

What this does:

  • Creates a Deployment
  • Runs 2 replicas (copies) of the container
  • Uses the Nginx image
  • Exposes port 80 inside the container

Step 4: Apply the Deployment

Run the following command:

kubectl apply -f deployment.yaml

Check deployment status:

kubectl get deployments

Check running pods:

kubectl get pods

You should see two pods running.

Step 5: Expose Your Application

Right now, your app is running but not accessible from outside the cluster.

To fix that, create a Service.

Step 6: Create a Service YAML File

Create a file:

service.yaml

Add this:

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

What this does:

  • Exposes your app externally
  • Maps port 80 inside the cluster to port 30007 on your machine

Step 7: Apply the Service

kubectl apply -f service.yaml

Verify:

kubectl get services

Step 8: Access Your Application

If you’re using Minikube:

minikube service my-first-service

This will open your browser and show the Nginx welcome page.

Step 9: Scale Your Application

One of Kubernetes’ strengths is scaling.

To scale from 2 pods to 4:

kubectl scale deployment my-first-app –replicas=4

Check pods:

kubectl get pods

Now you should see 4 running pods.

Step 10: Update Your Application

Let’s say you want to update your app version.

Edit your deployment:

kubectl edit deployment my-first-app

Change:

image: nginx:latest

To:

image: nginx:1.25

Kubernetes will automatically perform a rolling update no downtime.

Step 11: Monitor Your Application

Useful commands:

kubectl get allkubectl describe podkubectl logs

These help you debug and understand what’s happening.

Step 12: Clean Up Resources

Once you’re done, delete everything:

kubectl delete -f deployment.yaml kubectl delete -f service.yaml

Key Concepts Recap

Here are the main Kubernetes building blocks you just used:

  • Pod: Smallest unit, runs your container
  • Deployment: Manages pods and scaling
  • Service: Exposes your app to the network
  • Node: Machine running your workloads
  • Cluster: Group of nodes

Common Beginner Mistakes

  1. Forgetting labels and selectors
    If they don’t match, your service won’t connect to pods.
  2. Using wrong ports
    Always double-check containerPort vs targetPort vs nodePort.
  3. Not checking logs
    Logs are your best friend when debugging.

What’s Next?

Once you’re comfortable with this basic setup, you can explore:

  • Ingress controllers for better routing
  • Helm for package management
  • Persistent volumes for storage
  • CI/CD pipelines with Kubernetes

Final Thoughts

Kubernetes might seem complex at first, but the core workflow is straightforward:

  1. Define your application
  2. Deploy it using YAML
  3. Expose it with a service
  4. Scale and manage it

Start small, experiment often, and gradually build confidence.

Your first deployment is just the beginning.

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