13 KiB
Kubernetes Learning Lab Setup with Minikube on Debian 12
Prerequisites
- System Requirements:
- 2+ CPUs
- 2GB+ free memory
- 20GB+ free disk space
- Internet connection
- Software Requirements:
- Docker
- Kubectl
- Minikube
Setup Steps
1. Install Docker
- Update package list:
sudo apt-get update - Install required packages
- Add Docker's GPG key
- Set up Docker repository
- Install Docker Engine
- Start and enable Docker
- Verify installation
2. Install Kubectl
- Download latest release
- Make binary executable
- Move binary to PATH
- Verify installation
3. Install Minikube
- Download latest Minikube binary
- Install Minikube
- Verify installation
4. Start Minikube
- Start Minikube with Docker driver
- Verify Minikube status
5. Basic Minikube Commands
- Check cluster info
- Deploy sample application
- Access Minikube Dashboard
6. Stop and Delete Minikube
- Stop Minikube
- Delete Minikube
Sample Projects
1. Guestbook Application
- Components:
- Frontend: PHP-based web interface
- Backend: Redis master and replicas
- Deployment steps:
- Clone Kubernetes examples repository
- Deploy Redis Master (Deployment and Service)
- Deploy Redis Replicas (Deployment and Service)
- Deploy Guestbook Frontend (Deployment and Service)
- Verify and access the application
2. Simple Nginx Web Application
- Components:
- Nginx web server
- Static HTML page
- Deployment steps:
- Create Deployment YAML
- Create ConfigMap for HTML content
- Create Service YAML
- Deploy the application
- Access the application
- Clean up resources
Additional Learning Resources
- Kubernetes Documentation
- Katacoda Scenarios
- "Kubernetes Up and Running" book
- "Kubernetes the Hard Way" tutorial
For detailed instructions and commands, refer to the original document.
A good reference project for learning how to work with Kubernetes (K8s) should cover various aspects of K8s, including deployments, services, networking, storage, and scaling. One such project is the "Guestbook" application, a simple multi-tier web application that demonstrates many core concepts of Kubernetes.
Guestbook Application Overview
The Guestbook application consists of the following components:
- Frontend: A PHP-based web interface that users can interact with.
- Backend: A Redis master and a set of Redis replicas that store the guestbook entries.
Step-by-Step Guide to Deploy the Guestbook Application
Step 1: Clone the Kubernetes Examples Repository
First, clone the Kubernetes examples repository to get the configuration files for the Guestbook application.
git clone https://github.com/kubernetes/examples.git
cd examples/guestbook
Step 2: Deploy the Redis Master
-
Create a Redis Master Deployment:
apiVersion: apps/v1 kind: Deployment metadata: name: redis-master labels: app: redis tier: backend role: master spec: replicas: 1 selector: matchLabels: app: redis role: master tier: backend template: metadata: labels: app: redis role: master tier: backend spec: containers: - name: master image: redis ports: - containerPort: 6379 -
Create a Redis Master Service:
apiVersion: v1 kind: Service metadata: name: redis-master labels: app: redis tier: backend role: master spec: ports: - port: 6379 selector: app: redis role: master tier: backend
Apply these configurations:
kubectl apply -f redis-master-deployment.yaml
kubectl apply -f redis-master-service.yaml
Step 3: Deploy the Redis Replicas
-
Create a Redis Replica Deployment:
apiVersion: apps/v1 kind: Deployment metadata: name: redis-slave labels: app: redis tier: backend role: slave spec: replicas: 2 selector: matchLabels: app: redis role: slave tier: backend template: metadata: labels: app: redis role: slave tier: backend spec: containers: - name: slave image: gcr.io/google_samples/gb-redisslave:v3 ports: - containerPort: 6379 env: - name: GET_HOSTS_FROM value: dns -
Create a Redis Replica Service:
apiVersion: v1 kind: Service metadata: name: redis-slave labels: app: redis tier: backend role: slave spec: ports: - port: 6379 selector: app: redis role: slave tier: backend
Apply these configurations:
kubectl apply -f redis-slave-deployment.yaml
kubectl apply -f redis-slave-service.yaml
Step 4: Deploy the Guestbook Frontend
-
Create a Frontend Deployment:
apiVersion: apps/v1 kind: Deployment metadata: name: guestbook labels: app: guestbook tier: frontend spec: replicas: 3 selector: matchLabels: app: guestbook tier: frontend template: metadata: labels: app: guestbook tier: frontend spec: containers: - name: php-redis image: gcr.io/google-samples/gb-frontend:v4 ports: - containerPort: 80 -
Create a Frontend Service:
apiVersion: v1 kind: Service metadata: name: frontend labels: app: guestbook tier: frontend spec: type: LoadBalancer ports: - port: 80 selector: app: guestbook tier: frontend
Apply these configurations:
kubectl apply -f frontend-deployment.yaml
kubectl apply -f frontend-service.yaml
Step 5: Verify and Access the Application
-
Check the status of all deployments and services:
kubectl get deployments kubectl get services -
Access the frontend service using the Minikube service URL:
minikube service frontend
This will open the Guestbook application in your web browser.
Additional Learning Resources
- Kubernetes Documentation: The official Kubernetes documentation is a comprehensive resource.
- Katacoda Scenarios: Interactive Kubernetes tutorials on Katacoda.
- Kubernetes Up and Running: A great book by Kelsey Hightower, Brendan Burns, and Joe Beda.
- Kubernetes the Hard Way: A tutorial by Kelsey Hightower on GitHub.
This project will give you hands-on experience with deployments, services, scaling, and more, making it an excellent reference for learning Kubernetes.
Certainly! Let's deploy a more useful sample application—a simple web application that uses Nginx as a web server and serves a static HTML page. This example will cover the creation of a deployment, a service, and accessing the application.
Step 1: Create a Deployment YAML File
-
Create a file named
nginx-deployment.yamlwith the following content:apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment spec: replicas: 3 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:1.21.6 ports: - containerPort: 80 volumeMounts: - name: html mountPath: /usr/share/nginx/html volumes: - name: html configMap: name: html-configmap
Step 2: Create a ConfigMap for the HTML Page
-
Create a file named
html-configmap.yamlwith the following content:apiVersion: v1 kind: ConfigMap metadata: name: html-configmap data: index.html: | <!DOCTYPE html> <html> <head> <title>Welcome to Nginx</title> </head> <body> <h1>Welcome to your Nginx application!</h1> <p>Deployed with Minikube on Kubernetes.</p> </body> </html>
Step 3: Create a Service YAML File
-
Create a file named
nginx-service.yamlwith the following content:apiVersion: v1 kind: Service metadata: name: nginx-service spec: type: NodePort selector: app: nginx ports: - protocol: TCP port: 80 targetPort: 80 nodePort: 30007
Step 4: Deploy the Application
-
Apply the ConfigMap:
kubectl apply -f html-configmap.yaml -
Apply the Deployment:
kubectl apply -f nginx-deployment.yaml -
Apply the Service:
kubectl apply -f nginx-service.yaml
Step 5: Access the Application
-
Check the status of the pods to ensure they are running:
kubectl get pods -
Get the URL for the Nginx service:
minikube service nginx-service --url -
Open the URL in your web browser. You should see the static HTML page served by Nginx.
Step 6: Clean Up
-
To delete the resources, you can run:
kubectl delete -f nginx-service.yaml kubectl delete -f nginx-deployment.yaml kubectl delete -f html-configmap.yaml
This setup will provide you with a more useful and practical application deployment scenario, giving you a better understanding of how to work with Kubernetes deployments, services, and ConfigMaps.
Here's a step-by-step guide to set up Minikube on your Debian 12 system for a complete Kubernetes learning lab:
Prerequisites
-
System Requirements:
- 2 CPUs or more
- 2GB of free memory
- 20GB of free disk space
- Internet connection
-
Software Requirements:
- Docker
- Kubectl
- Minikube
Step 1: Install Docker
-
Update your package list:
sudo apt-get update -
Install required packages:
sudo apt-get install -y ca-certificates curl gnupg lsb-release -
Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg -
Set up the Docker repository:
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null -
Install Docker Engine:
sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin -
Start and enable Docker:
sudo systemctl start docker sudo systemctl enable docker -
Verify Docker installation:
sudo docker run hello-world
Step 2: Install Kubectl
-
Download the latest release:
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" -
Make the kubectl binary executable:
chmod +x kubectl -
Move the binary to your PATH:
sudo mv kubectl /usr/local/bin/ -
Verify the installation:
kubectl version --client
Step 3: Install Minikube
-
Download the latest Minikube binary:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -
Install Minikube:
sudo install minikube-linux-amd64 /usr/local/bin/minikube -
Verify the installation:
minikube version
Step 4: Start Minikube
-
Start Minikube with Docker driver:
minikube start --driver=docker -
Verify Minikube status:
minikube status
Step 5: Basic Minikube Commands
-
Check cluster info:
kubectl cluster-info -
Deploy a sample application:
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4 kubectl expose deployment hello-minikube --type=NodePort --port=8080 minikube service hello-minikube --url -
Access Minikube Dashboard:
minikube dashboard
Step 6: Stop and Delete Minikube
-
Stop Minikube:
minikube stop -
Delete Minikube:
minikube delete
Additional Resources
This setup will provide you with a complete learning lab for Kubernetes using Minikube on your Debian 12 system. Let me know if you need further assistance or have any questions!