Welcome to from-docker-to-kubernetes

Setup Your Environment

Install Your Container Tools

Step-by-step guide to setting up Docker, Kubernetes, and all the essential tools you need for container development.

banner

Prerequisites

Before beginning installation, ensure your system meets these requirements:

Hardware Requirements

  • CPU: 64-bit processor with virtualization support
  • RAM: Minimum 4GB (8GB+ recommended)
  • Storage: 20GB+ free disk space
  • Network: Internet connection for downloads

Operating System

  • Windows: Windows 10/11 (64-bit) Pro, Enterprise, or Education
  • macOS: macOS 10.15 (Catalina) or newer
  • Linux: Ubuntu 20.04+, Debian 10+, Fedora 34+, etc.

Additional Requirements

  • Windows only: WSL2 enabled
  • Linux only: sudo privileges
  • All platforms: Terminal/command-line familiarity

Docker Installation

Docker is the foundation of our containerization journey, allowing you to build and run containers on your local machine.

Docker consists of several components that work together:

  • Docker Engine: The core runtime that builds and runs containers
  • Docker CLI: Command-line interface for interacting with Docker
  • Docker Desktop: GUI application with additional tools (Windows/macOS)
  • Docker Compose: Tool for defining multi-container applications
  • Docker Hub: Public registry for sharing container images

Docker uses a client-server architecture where the Docker client communicates with the Docker daemon, which builds, runs, and manages containers.

Step 1: Install Docker Engine

Choose your operating system below and follow the installation instructions:

Docker on Linux

Docker runs natively on Linux and can be installed through package repositories:

# Update your package index
sudo apt-get update

# Install prerequisites for apt repositories over HTTPS
sudo apt-get install -y \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release \
    software-properties-common

# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add the Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update apt with the new repository
sudo apt-get update

# Install Docker Engine and related tools
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Alternative: Quick Installation Script

For testing environments, you can use Docker's convenience script:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Step 2: Verify Docker Installation

After installation, verify that Docker is working correctly with these commands:

# Check Docker version
docker --version

# View detailed system information
docker info

# Run a test container
docker run --rm hello-world

If Docker is installed correctly, the hello-world container will download (if not already present) and run, displaying a success message:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.
...

Step 3: Post-Installation Configuration

Complete your Docker setup with these additional configuration steps:

Linux Post-Installation Steps

Configure Docker to run without sudo and start on boot:

# Add your user to the docker group
sudo usermod -aG docker $USER

# Apply the new group membership (or log out and back in)
newgrp docker

# Enable Docker to start on boot
sudo systemctl enable docker.service
sudo systemctl enable containerd.service

# Verify you can run Docker without sudo
docker run --rm hello-world

Additional Linux Configuration (Optional)

Configure Docker daemon options by creating or editing /etc/docker/daemon.json:

{
  "default-address-pools": [
    {"base": "172.17.0.0/16", "size": 24}
  ],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "storage-driver": "overlay2",
  "features": {
    "buildkit": true
  }
}

After editing, restart Docker:

sudo systemctl restart docker

Kubernetes Tools Installation

Kubernetes allows you to orchestrate containers across multiple hosts. We'll install the essential tools for local Kubernetes development.

Step 1: Install kubectl

kubectl is the command-line tool for interacting with Kubernetes clusters:

Install kubectl on Linux

# Download the latest stable release
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"

# Validate the binary (optional but recommended)
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check

# Install kubectl
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl

# Verify installation
kubectl version --client

Alternative installation methods for Linux

Using package manager (Ubuntu/Debian):

# Add Kubernetes apt repository
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

# Install kubectl
sudo apt-get update
sudo apt-get install -y kubectl

Using snap:

sudo snap install kubectl --classic

Step 2: Install Minikube

Minikube creates a local single-node Kubernetes cluster for development and testing:

Install Minikube on Linux

# Download the latest Minikube binary
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64

# Make it executable and move to a directory in your PATH
sudo install minikube-linux-amd64 /usr/local/bin/minikube

# Verify installation
minikube version

Choose a driver for Minikube

Minikube needs a "driver" to create the Kubernetes cluster. On Linux, you have several options:

Docker driver (recommended if Docker is installed):

minikube config set driver docker

KVM driver (requires KVM installation):

# Install KVM
sudo apt-get install -y qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils

# Install the KVM driver for Minikube
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2 && \
chmod +x docker-machine-driver-kvm2 && \
sudo mv docker-machine-driver-kvm2 /usr/local/bin/

# Configure Minikube to use KVM
minikube config set driver kvm2

VirtualBox driver (requires VirtualBox installation):

# Install VirtualBox
sudo apt-get install -y virtualbox

# Configure Minikube to use VirtualBox
minikube config set driver virtualbox

Step 3: Start Your First Kubernetes Cluster

Now that Minikube is installed, let's create your first local Kubernetes cluster:

# Start Minikube with default settings
minikube start

# Check cluster status
minikube status

# View cluster information
kubectl cluster-info

# View nodes in the cluster
kubectl get nodes

If successful, you should see output similar to:

šŸ˜„  minikube v1.31.2 on Linux 5.15.0-60-generic
✨  Using the docker driver based on existing profile
šŸ‘  Starting control plane node minikube in cluster minikube
🚜  Pulling base image ...
šŸ”„  Restarting existing docker container for "minikube" ...
🐳  Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
šŸ”Ž  Verifying Kubernetes components...
    ā–Ŗ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟  Enabled addons: default-storageclass, storage-provisioner
šŸ„  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

Step 4: Install Helm (Optional)

Helm is the package manager for Kubernetes, helping you install and manage applications on your cluster:

Install Helm on Linux

Using script installer (recommended):

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

# Verify installation
helm version

Alternative Installation Methods:

# Debian/Ubuntu
sudo apt-get update
sudo apt-get install helm

# CentOS/RHEL
sudo yum install helm

# Snap
sudo snap install helm --classic

Additional Tools (Optional)

Consider these additional tools to enhance your Kubernetes development experience:

Kubernetes Dashboard

A web-based UI for Kubernetes clusters
# Enable the dashboard in Minikube
minikube addons enable dashboard

# Access the dashboard
minikube dashboard

Lens

An IDE for KubernetesDownload from k8slens.dev

kubectx & kubens

Tools for switching between contexts and namespaces
# Install on Linux/macOS
brew install kubectx

# Install on Windows
choco install kubectx

k9s

Terminal UI for Kubernetes
# Install on Linux/macOS
brew install k9s

# Install on Windows
choco install k9s

Verifying Your Installation

Now that you've installed all the necessary components, let's verify that everything is working correctly by performing some basic tests. This will ensure your development environment is properly set up before you start building applications.

Step 1: Verify Docker

Let's first confirm that Docker is functioning properly by running a few simple commands:

# Run a simple container and verify output
docker run --rm alpine echo "Hello from Docker container!"

This command pulls the lightweight Alpine Linux image (if not already present) and runs a container that displays a hello message. The --rm flag ensures the container is automatically removed after execution.

# List running containers to verify Docker daemon is responsive
docker ps

You should see a list of running containers (which might be empty if you don't have any containers running).

# Create a simple Docker network to test network functionality
docker network create test-network

# Verify the network was created
docker network ls | grep test-network

# Remove the test network when done
docker network rm test-network

If these commands execute without errors, your Docker installation is working correctly.

Step 2: Verify Kubernetes

Now, let's verify that your Kubernetes cluster is running and can deploy applications:

# Check that Minikube is running with proper status
minikube status

You should see output indicating that Minikube is running, with the host, kubelet, and apiserver all showing "Running" status.

# Deploy a simple test application to your cluster
kubectl create deployment hello-kubernetes --image=k8s.gcr.io/echoserver:1.4

# Expose the deployment as a NodePort service
kubectl expose deployment hello-kubernetes --type=NodePort --port=8080

# Wait a moment for the pod to be ready
kubectl wait --for=condition=ready pod -l app=hello-kubernetes --timeout=60s

Let's check what we've created:

# Verify the pod is running
kubectl get pods -l app=hello-kubernetes

# Examine the created service
kubectl get services hello-kubernetes

# Get detailed information about our deployment
kubectl describe deployment hello-kubernetes

Finally, let's access our application:

# Open the service in your default browser
minikube service hello-kubernetes

Step 3: Clean Up Test Resources

Once you've verified everything is working, let's clean up the test resources:

# Delete the service we created
kubectl delete service hello-kubernetes

# Delete the deployment
kubectl delete deployment hello-kubernetes

# Verify resources were removed
kubectl get all | grep hello-kubernetes

The last command should return no results, indicating all resources have been successfully removed.

Next Steps

Now that you have a working Docker and Kubernetes environment, you're ready to start building, deploying, and managing containerized applications! In the next sections, we'll explore how to create Docker images, work with containers, and deploy applications to Kubernetes.

What You've Accomplished

You now have a fully functional local development environment with:
  • Docker for container management
  • Minikube for local Kubernetes development
  • kubectl for interacting with Kubernetes clusters
  • Essential tools for containerized application development

Where To Go Next

  • Learn Docker basics and build your first container
  • Understand Kubernetes concepts and architecture
  • Deploy multi-container applications with Kubernetes
  • Explore advanced deployment patterns