Deploy Docker To Kubernetes

Deploy Docker To Kubernetes

Reading time1 min
#Cloud#DevOps#Containers#Docker#Kubernetes#Containerization

Seamless Transition: Deploying Docker Containers on Kubernetes Without the Complexity Overhead

As organizations shift from simple containerization to scalable orchestration, understanding how to deploy Docker containers efficiently on Kubernetes is crucial to maximize resource utilization and ensure reliable app delivery.


Forget the Assumption: Kubernetes Deployment is NOT Inherently Complex

If you’re a developer or DevOps engineer comfortable with Docker, you might hesitate when it comes to deploying your containers on Kubernetes. The assumption often is that Kubernetes (K8s) demands a steep learning curve and complex setup, but that’s not necessarily true. In fact, with your existing Docker knowledge and configurations, you can orchestrate your apps on Kubernetes with minimal friction.

Today, I’ll walk you through a straightforward process to deploy your Docker container onto a Kubernetes cluster — keeping things practical, clear, and avoiding common pitfalls often encountered during this transition.


Why Move Docker Containers to Kubernetes?

Before diving into the how-to, here’s the what and why:

  • Docker handles containerization and is fantastic for building and running containers locally or on a single node.

  • Kubernetes offers orchestration — managing multiple containers across nodes, scaling apps automatically, handling failures gracefully.

Deploying Docker containers on K8s lets you retain your current images while gaining scalability and resilience benefits.


Step-by-Step Guide: From Docker Container to Kubernetes Deployment

1. Prepare Your Docker Image

Ensure you have a working Docker image. For example, if you have a simple Node.js app:

# Dockerfile
FROM node:14-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "server.js"]
EXPOSE 3000

Build and tag your image locally:

docker build -t yourusername/my-node-app:latest .

Test it locally:

docker run -p 3000:3000 yourusername/my-node-app:latest

If everything’s working here, the first step is done!


2. Push Your Image to a Container Registry

Kubernetes pulls images from registries like Docker Hub or private registries. Push your image so K8s can access it:

docker login
docker push yourusername/my-node-app:latest

3. Set Up a Kubernetes Cluster

If you don’t already have a cluster:

  • Use Minikube or kind for local testing
  • Use managed services like GKE, EKS, or AKS for production-like environments

For local testing with Minikube:

minikube start
kubectl config use-context minikube

4. Write Your Kubernetes Deployment YAML

Here’s a minimal deployment definition that uses your existing image:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-node-app-deployment
spec:
  replicas: 3 # scale to three pods for reliability & load balancing 
  selector:
    matchLabels:
      app: my-node-app
  template:
    metadata:
      labels:
        app: my-node-app
    spec:
      containers:
      - name: my-node-container
        image: yourusername/my-node-app:latest
        ports:
        - containerPort: 3000

Create this file as deployment.yaml.


5. Apply Your Deployment

Deploy it using kubectl:

kubectl apply -f deployment.yaml

Check the status of pods:

kubectl get pods -l app=my-node-app

You should see three pods running as per the replica count.


6. Expose Your Deployment (Optional: Create a Service)

To access your application outside the cluster (e.g., from localhost), expose it via NodePort or LoadBalancer service.

Example service YAML (service.yaml):

apiVersion: v1
kind: Service
metadata:
  name: my-node-service
spec:
  type: NodePort # For local clusters; use LoadBalancer in cloud environments 
  selector:
    app: my-node-app 
  ports:
    - protocol: TCP
      port: 80        # The port exposed inside the cluster 
      targetPort: 3000 # The port on the container 
      nodePort: 30001 # The port accessible on localhost (Minikube)

Apply service:

kubectl apply -f service.yaml 

Find Minikube IP and access via http://<minikube-ip>:30001

minikube ip 
curl http://$(minikube ip):30001 

Key Tips to Avoid Common Pitfalls

  • Keep container ports aligned: The containerPort in deployment must match what your app listens on.

  • Check image tags carefully: Use explicit tags rather than latest in production.

  • Use namespace if desired: Organize deployments logically by namespacing.

  • Leverage kubectl rollout status: Helps monitor deployment progress.

kubectl rollout status deployment/my-node-app-deployment  
  • Use ConfigMaps/Secrets when scaling: Avoid baking configs into images for flexibility in K8s.

Wrapping Up

Transitioning from using standalone Docker containers to deploying them in Kubernetes doesn’t need to be overwhelming. With these steps:

  • Build & push your familiar Docker image,
  • Write simple YAML manifests,
  • Use straightforward commands,

you can leverage powerful orchestration without drowning in complexity.

Start small with deployments like this one; gradually explore advanced features like ingress controllers, autoscaling, and monitoring once comfortable.

Your existing Docker expertise is more than enough to get started with Kubernetes — it’s about layering orchestration over what you already know.

Have questions or want me to cover specific scenarios? Drop them in the comments!


Happy containerizing! 🚀