DEV Community

Cover image for Getting Started with Kubernetes: Orchestrating My Docker Containers
Daniel Azevedo
Daniel Azevedo

Posted on

Getting Started with Kubernetes: Orchestrating My Docker Containers

Hi devs :)

After diving into Docker and understanding the power of containers, I realized it was time to explore Kubernetes—the leading platform for container orchestration. While Docker helps me manage individual containers, Kubernetes takes things to the next level by managing clusters of containers across multiple hosts. In this post, I’ll share my initial insights into Kubernetes and how it fits into my containerization journey.

What Is Kubernetes?

Kubernetes, often referred to as K8s, is an open-source platform designed to automate deploying, scaling, and operating application containers. It was originally developed by Google and has become a standard for container orchestration.

Why Use Kubernetes?

  1. Scaling Applications: Kubernetes makes it easy to scale applications up or down based on demand. For example, if my web app gets a surge in traffic, I can quickly scale up the number of container instances to handle the load.

  2. Load Balancing: K8s automatically distributes traffic across containers, ensuring that no single instance is overwhelmed. This improves reliability and performance.

  3. Self-Healing: If a container crashes, Kubernetes automatically replaces it, keeping the application running without manual intervention.

  4. Declarative Configuration: With Kubernetes, I can define the desired state of my application in YAML files. Kubernetes will then ensure that the current state matches the desired state, making deployment predictable and manageable.

My First Kubernetes Experience

To get started, I set up a local Kubernetes environment using Minikube. This allowed me to run a single-node Kubernetes cluster on my laptop, perfect for development and experimentation.

Installing Minikube

  1. Install Minikube: I followed the instructions on the Minikube website to get it set up. It's pretty straightforward!

  2. Start Minikube: I ran the command:

   minikube start
Enter fullscreen mode Exit fullscreen mode
  1. Verify Installation: To check that everything was running, I used:
   kubectl get nodes
Enter fullscreen mode Exit fullscreen mode

Deploying My First Application

I decided to deploy a simple Node.js application to see how Kubernetes works. Here’s the process:

  1. Create a Deployment: I defined a deployment in a deployment.yaml file:
   apiVersion: apps/v1
   kind: Deployment
   metadata:
     name: my-node-app
   spec:
     replicas: 3
     selector:
       matchLabels:
         app: my-node-app
     template:
       metadata:
         labels:
           app: my-node-app
       spec:
         containers:
         - name: my-node-app
           image: my-node-app:latest
           ports:
           - containerPort: 3000
Enter fullscreen mode Exit fullscreen mode

This file specifies that I want three replicas of my Node.js application running.

  1. Apply the Deployment: I used kubectl to create the deployment:
   kubectl apply -f deployment.yaml
Enter fullscreen mode Exit fullscreen mode
  1. Expose the Application: To access my app from outside the cluster, I created a service:
   apiVersion: v1
   kind: Service
   metadata:
     name: my-node-app-service
   spec:
     type: NodePort
     selector:
       app: my-node-app
     ports:
       - port: 3000
         targetPort: 3000
         nodePort: 30001
Enter fullscreen mode Exit fullscreen mode

I applied this with:

   kubectl apply -f service.yaml
Enter fullscreen mode Exit fullscreen mode
  1. Accessing the App: Now I can access my Node.js app by navigating to http://localhost:30001.

Next Steps

As I get more comfortable with Kubernetes, I’m excited to explore features like:

  • Persistent Volumes: For managing data that needs to be stored beyond the lifecycle of a pod.
  • Helm Charts: For managing complex applications using package management.
  • Monitoring and Logging: To keep track of application performance and troubleshoot issues.

Conclusion

Kubernetes is a powerful tool that complements what I’ve learned about Docker. While Docker focuses on individual containers, Kubernetes orchestrates those containers at scale, bringing a new level of control and flexibility to my applications.

If you’re considering exploring Kubernetes, I highly recommend it! There’s a bit of a learning curve, but the benefits of orchestration and management are well worth the effort.

What are your experiences with Kubernetes? Any tips for a beginner like me? I’d love to hear your thoughts!

Top comments (0)