Getting started with Gefyra and k3d
This guide will show you how to use Gefyra for the local development of a Kubernetes application running in k3d.
Prerequisites
- Follow the installation for your preferred platform.
Hint there is a bug in Docker Desktop v4.17-v4.18 which causes gefyra up
to fail with k3d clusters that run on that DD version.
- Create a local Kubernetes cluster with
k3d
like so:
< v5k3d cluster create mycluster --agents 1 -p 8080:80@agent[0] -p 31820:31820/UDP@agent[0]
>= v5
k3d cluster create mycluster --agents 1 -p 8080:80@agent:0 -p 31820:31820/UDP@agent:0
This creates a Kubernetes cluster that binds port 8080 and 31820 to localhost.
kubectl
context is immediately set to this cluster. - Apply some workload, for example from the testing directory of this repo:
kubectl apply -f https://raw.githubusercontent.com/gefyrahq/gefyra/main/testing/workloads/hello.yaml
Check out this workload running under: http://hello.127.0.0.1.nip.io:8080/
Running Gefyra
- Set up Gefyra with
gefyra up
- Run a local Docker image with Gefyra in order to make it part of the cluster.
- Build your Docker image with a local tag, for example from the testing directory:
cd testing/images/ && docker build -f Dockerfile.local . -t pyserver
- Execute Gefyra’s run command:
gefyra run -i pyserver -N mypyserver -n default
- Exec into the running container and look around. You will find the container to run within your Kubernetes cluster.
docker exec -it mypyserver bash
wget -O- hello-nginx
will print out the website of the cluster service hello-nginx from within the cluster.
- Build your Docker image with a local tag, for example from the testing directory:
- Create a bridge in order to intercept the traffic to the cluster application with the one running locally:
gefyra bridge -N mypyserver -n default --port 8000:80 --target deploy/hello-nginxdemo/hello-nginx
Check out the locally running server comes up under: http://hello.127.0.0.1.nip.io:8080/
- List all running bridges:
gefyra list --bridges
- Unbridge the local container and reset the cluster to its original state:
gefyra unbridge -N mypybridge
Check out the initial response from: http://hello.127.0.0.1.nip.io:8080/
Cleaning up
- Remove Gefyra’s components from the cluster with
gefyra down
- Remove the locally running Kubernetes cluster with
k3d cluster delete mycluster