Setting Up Kubernetes Locally with K3d
๐ Welcome to the Ultimate Guide on Setting Up Kubernetes Locally with Docker Desktop and NGINX Ingress! ๐
Are you ready to dive into the exciting world of Kubernetes without leaving the comfort of your local machine? Letโs get started!
๐ฅ Step 1: Install Docker Desktop
First things first, you need Docker Desktop on your machine. Itโs your gateway to running Kubernetes locally.
- ๐ Download and Install: Head over to the Docker Desktop website and grab the installer for your OS.
๐ Step 2: Enable Kubernetes in Docker Desktop
Once Docker is cozy on your machine, itโs time to awaken the Kubernetes beast within it.
- โ Enable Kubernetes: Open Docker Desktop, find your way to Preferences > Kubernetes, and tick the โEnable Kubernetesโ box.
- ๐ Apply & Restart: Hit โApply & Restartโ and watch the magic happen!
๐ฆ Step 3: Install NGINX Ingress Controller
Kubernetes is cool, but it needs a trusty Ingress controller to manage traffic. And NGINX is our hero here.
- ๐บ๏ธ Install via Helm: Helm is like your Kubernetes treasure map. Follow the instructions on the Helm website to get it. Then run these commands:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx helm repo update helm install nginx-ingress ingress-nginx/ingress-nginx
๐๏ธ Step 4: Configure DNS Using Hosts File
Time to play with the hosts file to make your local DNS play nice with Kubernetes.
- ๐ Edit Hosts File: This file is hiding at
/etc/hosts
on Linux and macOS, andC:\Windows\System32\Drivers\etc\hosts
on Windows. Add lines like these:127.0.0.1 myservice.local 127.0.0.1 anotherservice.local
๐ Step 5: Deploy Your Application
Letโs get your app into the Kubernetes playground!
- ๐ Create Kubernetes Manifests: Whip up some YAML files for your deployment and service. Hereโs a sample to get you started:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
selector:
matchLabels:
app: my-app
replicas: 2
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-app-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 80
๐ฃ๏ธ Step 6: Create Ingress Resource
We need some rules to tell NGINX how to route that traffic.
- ๐ Define Ingress Rules: Craft an Ingress YAML that looks something like this:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: myservice.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-service
port:
number: 80
โ Step 7: Apply Your Configuration
Almost there! Letโs make Kubernetes aware of your grand plans.
- ๐ง Apply with kubectl: Run these
kubectl apply -f <your-deployment.yaml>
kubectl apply -f <your-ingress.yaml>
๐ Step 8: Test Your Setup
Moment of truth! Open your browser and go to http://myservice.local
. Fingers crossed! ๐ค
๐ Troubleshooting Tips: If things go sideways, peek into the NGINX Ingress controller logs and your podsโ logs.
Remember, this is your local Kubernetes playground. In the real world, youโd have an external IP or a proper domain name instead of localhost
.
Thatโs it! Youโve just set up a Kubernetes environment locally with Docker Desktop and NGINX Ingress. Happy coding! ๐ป๐
Leave a comment