

Building a local Kubernetes cluster using k3d
source link: https://dev.to/iamunnip/building-a-local-kubernetes-cluster-using-k3d-2p3d
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Posted on Oct 18
Building a local Kubernetes cluster using k3d
k3d is a lightweight wrapper to run k3s (minimal Kubernetes distribution from Rancher Labs) in Docker.
By using k3d, we can create single and multi node k3s clusters in Docker for local development purpose.
In this blog, we are going to use Ubuntu 20.04 LTS for setting up k3d.
Install Docker using the convenience script
$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh
Add your user to the docker group to execute commands as non-root user and log out from the current session
$ sudo usermod -aG docker $USER
Log back in and verify the Docker commands as non-root user
$ docker info
$ docker container run hello-world
Download and install k3d
$ curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash
$ k3d version
Download and install kubectl
$ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
$ sudo install kubectl /usr/local/bin/kubectl
$ kubectl version --client
Create the cluster using the below configuration file
$ cat config.yml
apiVersion: k3d.io/v1alpha4
kind: Simple
metadata:
name: dev
servers: 1
agents: 2
image: rancher/k3s:v1.25.2-k3s1
ports:
- port: 30000-30100:30000-30100
nodeFilters:
- server:*
registries:
create:
name: dev
host: 0.0.0.0
hostPort: "5000"
options:
k3s:
extraArgs:
- arg: --disable=traefik
nodeFilters:
- server:*
$ k3d cluster create --config config.yml
Check the cluster details and nodes
$ kubectl cluster-info
$ kubectl get nodes
Create a sample index.html file
$ echo "Hello from Pod!" > index.html
Build a custom Docker image using the below Dockerfile
$ cat Dockerfile
FROM nginx:1.23
COPY index.html /usr/local/nginx/html
$ docker image build -t app:v1 .
Tag the custom built image and push to the container registry created by k3d
$ docker image tag app:v1 localhost:5000/app:v1
$ docker image push localhost:5000/app:v1
Deploy a pod using the custom built image
$ cat app-pod.yml
apiVersion: v1
kind: Pod
metadata:
labels:
run: app
name: app
spec:
containers:
- image: dev:5000/app:v1
name: app
ports:
- containerPort: 80
$ kubectl create -f app-pod.yml
$ kubectl get pods
Expose the pod to a node port service
$ cat app-nodeport.yml
apiVersion: v1
kind: Service
metadata:
labels:
run: app
name: app-nodeport
spec:
ports:
- port: 80
targetPort: 80
nodePort: 30000
selector:
run: app
type: NodePort
$ kubectl create -f app-nodeport.yml
$ kubectl get svc
Verify the webpage using browser or curl
$ curl http://localhost:30000
Recommend
-
13
Now that we have our vSphere with Kubernetes
-
17
K3s with k3d and MetalLB
-
8
Building a Twitter Bot using IPFS Cluster 🤖Till now, we have explored a number of fun examples using InterPlanetary File System (IPFS),
-
15
TL;DR If you want to use Helm, but not Azure Dev Spaces. You can do it manually following
-
7
Debugging the Kubernetes Autoscaler using Cluster API and Docker 22 May 2020 In my previous post I gave a little background on the Cluster...
-
6
k3d入门指南:在Docker中运行K3s ...
-
7
Home Menu k3d - first contact...
-
10
-
17
Introduction Why do you need this? For local development you want to connect to a remote Kafka Cluster running on OpenShift , that is deployed using Strimzi Operator Prerequisite
-
5
k3d 国内加速下载k3d 国内加速下载 2023-02-12 2k3d. 国内直接从官网(https://github...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK