I often have the need to run a workload on Kubernetes, but just temporarily and therefore I don’t want to create a fully-fledged cluster in the cloud. Some smaller, local setup often works in my case and I believe this would be the case for a lot of developers.
RancherLab has done a phenomenal job in providing the minimal Kubernetes distribution k3s which is great for edge computing and IoT. In my case, I want to run it on my MacBook which wouldn’t work out-of-the-box. K3d on the other hand provides a wrapper for k3s to run it in docker. Problem solved!
K3d + Istio
For my use case, I also want to run a service mesh and my initial thought was to use Istio, as it is widely used and eventually I want to run the cloud-native application life-cycle orchestrator Keptn locally which also makes use of Istio. (However, in this blog I focus solely on k3d + Istio)
Run it locally
Running k3d + Istio locally on Mac, Linux or Windows doesn’t require any voodoo. Just be careful with some options when running it. I’ll explain them in the following, so you can follow my approach.
Prerequisites: Docker and some kind of shell. I am running on zsh on MacOS but pretty sure the same steps work on Linux and WSL.
wget -q -O - https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
Start a local cluster
k3d cluster create myistiocluster -p "8082:80@agent" -p "8443:443@agent" --k3s-server-arg '--no-deploy=traefik' --agents 1
In this case we need to make sure to disable traefik to avoid port conflicts. I’ll also map local ports 8082 and 8443 to the ports of k3d to make them available for later use.
Cluster now running — great!
INFO Prep: Network
INFO Created network 'k3d-myistiocluster' (2bf77591ba17a66612be91bf07bba5fd9be46a89ce6cb9f9071d2cea2016b5d6)
INFO Created volume 'k3d-myistiocluster-images'
INFO Creating node 'k3d-myistiocluster-server-0'
INFO Creating node 'k3d-myistiocluster-agent-0'
INFO Creating LoadBalancer 'k3d-myistiocluster-serverlb'
INFO Starting cluster 'myistiocluster'
INFO Starting servers...
INFO Starting Node 'k3d-myistiocluster-server-0'
INFO Starting agents...
INFO Starting Node 'k3d-myistiocluster-agent-0'
INFO Starting helpers...
INFO Starting Node 'k3d-myistiocluster-serverlb'
INFO (Optional) Trying to get IP of the docker host and inject it into the cluster as 'host.k3d.internal' for easy access
INFO Successfully added host record to /etc/hosts in 3/3 nodes and to the CoreDNS ConfigMap
INFO Cluster 'myistiocluster' created successfully!
Make sure to configure kubectl to point to your new cluster
kubectl config use-context k3d-myistiocluster
Next, get the Istio CLI.
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.10.0 sh -
Install Istio into the local cluster.
Now let’s verify that Istio is running in the cluster:
kubectl get pods -ANAMESPACE NAME READY STATUS RESTARTS AGE
kube-system local-path-provisioner-5ff76fc89d-dr9wm 1/1 Running 0 5m28s
kube-system metrics-server-86cbb8457f-df8wl 1/1 Running 0 5m28s
kube-system coredns-854c77959c-8jbkc 1/1 Running 0 5m28s
istio-system istiod-79dd646bcd-mptql 1/1 Running 0 3m2s
istio-system svclb-istio-ingressgateway-87dxt 3/3 Running 0 2m14s
istio-system svclb-istio-ingressgateway-8jhx2 3/3 Running 0 2m14s
istio-system istio-ingressgateway-8579cc48f8-hlnc8 1/1 Running 0 2m15s
Next, let’smdeploy the bookinfo demo application that comes with Istio. Make sure to move into the folder of the Istio installer that we’ve downloaded earlier.
cd istio-1.10.0kubectl label namespace default istio-injection=enabledkubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
Let’s verify that all services are available:
kubectl get svcNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 10m
details ClusterIP 10.43.209.51 <none> 9080/TCP 3m45s
ratings ClusterIP 10.43.163.170 <none> 9080/TCP 3m45s
reviews ClusterIP 10.43.149.170 <none> 9080/TCP 3m45s
productpage ClusterIP 10.43.242.170 <none> 9080/TCP 3m45s
Now, let’s create the Ingress Gateway for our application to be able to access it via localhost.
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
Finally, we can verify that everything is working by opening a browser on http://localhost:8082/productpage and having a look at the productpage
Congrats — Installation done!
You’ve successfully set up a local Kubernetes cluster + Istio and exposed it on localhost. If you ever want to stop and restart your cluster, you can do via the following commands:
# stop the cluster
k3d cluster stop myistiocluster# start it again
k3d cluster start myistiocluster