How to Migrate Docker Apps to Kubernetes

When I first started using Docker, I thought it was the coolest way to run apps. It made everything neat and tidy. I could put my app, settings, and files in one box and move it anywhere. But later, when I had more than a few apps running, things got a bit messy. That’s when I met Kubernetes.

Now, Kubernetes (people call it “K8s”) is like the boss of a container village. It helps you organize, manage, and keep your Docker apps running smoothly—even if your system crashes. Sounds smart, right?

So, in this article, I’ll show you how to move from using Docker alone to using Kubernetes. I’ve done this myself, and I’ll walk you through it like a friend would.


What Are Docker and Kubernetes?

Let’s break this down.

  • Docker is a tool that lets you package your app and everything it needs (like libraries or code) into a container. Think of it like putting your app in a suitcase—you can move it anywhere and it will still work.
  • Kubernetes is a system that helps you manage lots of these containers. It’s like having a manager who knows where every suitcase goes, when to open it, and how to handle problems when something breaks.

You don’t need Kubernetes if you only run one or two apps. But if you’re running many apps, or your app needs to always stay up, even during updates, Kubernetes is worth learning.


Why Migrate from Docker to Kubernetes?

You might ask, “Why should I bother?”

I had the same question. But here’s what I learned:

Benefits of Kubernetes:

  • It restarts your app if it crashes. No more babysitting.
  • It balances traffic, so if too many people use your app at once, it can make more copies of the app to handle the load.
  • It keeps your app available, even when you’re updating it.
  • It helps you grow. If your project gets bigger, Kubernetes scales with you.

Using Docker alone is like running a food cart. Using Kubernetes is like running a whole food court—with helpers and backup plans.


What You Need Before Starting

Before you move your Docker app to Kubernetes, you need a few things:

  1. A working Docker app. This means your app runs fine inside a Docker container.
  2. Basic Kubernetes knowledge. If you can run simple commands like kubectl get pods, you’re good.
  3. A local Kubernetes environment. You can use:
    • Minikube – for running Kubernetes locally
    • Kind – Kubernetes in Docker (very meta, I know)
    • Docker Desktop – it now comes with a Kubernetes option
  4. Your brain and some snacks. Trust me, snacks help.

Step-by-Step: Migrating Docker Apps to Kubernetes

Let’s walk through the process. I’ll use a simple web app as an example.


1. Make Sure Your Docker App Works

Test your app with:

docker build -t myapp .
docker run -p 8080:80 myapp

If it works in your browser at localhost:8080, you’re golden.


2. Push the Docker Image to a Registry

You need to upload your image somewhere Kubernetes can reach it.

You can use:

  • Docker Hub
  • GitHub Container Registry
  • Google Container Registry

Example:

docker tag myapp yourname/myapp
docker push yourname/myapp

Kubernetes will later pull this image.


3. Write a Kubernetes Deployment File

Here’s a simple deployment.yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: yourname/myapp
        ports:
        - containerPort: 80

What this does:
It tells Kubernetes to run 2 copies of your app using the image you uploaded. It maps port 80 inside the container.

Funny thing: if you make a typo in the file, Kubernetes won’t yell at you—it’ll just crash politely.


4. Apply the Deployment

Run this in your terminal:

kubectl apply -f deployment.yaml

Check the pods:

kubectl get pods

If you see your pods listed and status is “Running”, you did it right. You can give yourself a cookie.


5. Expose the App with a Service

You need a way to access your app.

Here’s a simple service.yaml:

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

Apply it:

kubectl apply -f service.yaml

Now, open your browser and go to:

http://localhost:30007

Ta-da! Your Docker app is now running on Kubernetes.


How Is Kubernetes Different from Docker?

Here’s a little comparison to help:

Feature Docker Kubernetes
App Packaging ✅ Yes ✅ Yes (uses Docker)
Auto Recovery ❌ No ✅ Yes
Load Balancing ❌ No ✅ Yes
Scaling Apps Manual Automatic
Updating Apps Stop & Start Smooth rolling updates
Good for Simple projects Growing or complex apps

You see? Kubernetes is like Docker with superpowers. Or like upgrading from a tricycle to a bicycle with training wheels.


Common Mistakes to Avoid

Even I messed up a few times, so here are some tips to save you from pain:

  • Forget to push image – Your app won’t start if Kubernetes can’t find your Docker image.
  • Wrong ports – Be careful when matching container ports and service ports.
  • Missing labels – Kubernetes uses labels to connect things. Miss them, and stuff breaks quietly.
  • Not watching logs – If something goes wrong, run:
    kubectl logs <pod-name>
    

What About Docker Compose?

You may already use docker-compose.yml. Don’t worry, you can turn that into Kubernetes too.

There’s a tool called kompose that converts your Docker Compose file into Kubernetes YAML.

kompose convert

It’s not perfect, but it’s a good start.


Two Lists to Help You

Tools That Help With Kubernetes:

  • Lens – GUI to manage your clusters
  • k9s – Terminal tool to view pods, logs, etc.
  • Helm – Package manager for Kubernetes
  • Skaffold – Helps with CI/CD and development

Kubernetes Concepts to Know:

  • Pod – The smallest unit in Kubernetes (like a container)
  • Service – Makes your app reachable
  • Deployment – Tells Kubernetes how to run your app
  • ConfigMap – Stores configuration data
  • Secret – Like ConfigMap but for sensitive stuff (like passwords)

Wrapping Up

So, we’ve covered a lot. But don’t worry if it takes a few tries. It took me three attempts just to get the service part working right. But each try helped me learn.

Moving from Docker to Kubernetes may feel like a big leap, but it’s doable—especially if you take it one step at a time.

Remember:

  • Test your Docker app first.
  • Push your image.
  • Write clear YAML files.
  • Use kubectl often.

And when in doubt, ask for help or peek at logs. Kubernetes is powerful, but it also expects you to be a bit more organized.

Also, if your app doesn’t start, don’t panic—it might just be container-napping. Give it a gentle prod with kubectl logs.


Final Thoughts

You don’t need to know everything at once. Just start. Like I did.
You’ll mess up. I did too.
But once your app is flying high in Kubernetes, you’ll feel like a tech magician.

Now go give your Docker app a better home—with Kubernetes as its new boss.

If this guide helped you, or made you chuckle, maybe share it with a friend who’s stuck in Dockerland. They might need a lift too.

Need more help? You can always ask me again.

And remember, containers may be small—but your skills? Container-sized and growing. 😄

Leave a Reply