NOTES INDEX This page is part of the collection of "notes" - these can be considered to be micro-blogs.
Kind == Mini Kubernetes Cluster

Kind == Mini Kubernetes Cluster

If you need to run a local (mini) Kubernetes cluster for some simple tests, you can try “Kind”. In seems to runs inside a single docker image (so you need docker on your machine).

See on how to install it.

Example installation (GoLang example):

# if you have GoLang installed, you can try it like this (see kind site for latest version to use): go install
Code language: Bash (bash)

If Kind was installed, you can use a simple cluster create command:

kind create cluster
Code language: Bash (bash)

Or create it like this (from Linux command line) if you need special settings -for example needed if you want to use kubectl debug:

cat <<EOF | kind create cluster --config=- kind: Cluster apiVersion: kubeadmConfigPatches: # enable EphemeralContainers feature gate - | kind: ClusterConfiguration metadata: name: config apiServer: extraArgs: "feature-gates": "EphemeralContainers=true" scheduler: extraArgs: "feature-gates": "EphemeralContainers=true" controllerManager: extraArgs: "feature-gates": "EphemeralContainers=true" - | kind: InitConfiguration metadata: name: config nodeRegistration: kubeletExtraArgs: "feature-gates": "EphemeralContainers=true" - | kind: KubeletConfiguration featureGates: EphemeralContainers: true - | kind: KubeProxyConfiguration featureGates: EphemeralContainers: true EOF
Code language: Bash (bash)

After creation, your local .kube/config is updated to point to the created cluster.

To delete the cluster after use, execute:

kind delete cluster
Code language: Bash (bash)

If you have helm3 installed locally, you can for example install an ingress controller using this:

helm3 repo add ingress-nginx helm3 repo update helm3 install ingress-nginx ingress-nginx/ingress-nginx
Code language: Bash (bash)

And assuming you have kubectl installed, you can check upon the cluster:

kubectl get nodes kubectl get pods --all-namespaces
Code language: Bash (bash)

And just for fun, if you want to connect to the network layer of the running ingress controller, you can use:

# start debug container, using network layer of the named pod kubectl debug -it ingress-nginx-controller-54bfb9bb-tnvpk --image=ubuntu # inside the ubuntu pod, type (to use curl on the ingress container): apt-get update apt-get install -y curl net-tools curl -v # or in the ubuntu pod, type (to show/trace network traffic): apt-get update apt-get install -y tcpdump net-tools # then find the network interface (probably is eth0:): ifconfig #start tcpdump (use your network interface in the spot of eth0 if it was different) tcpdump -i eth0 -Al -s0 port 80 # then from another command line, start a test pod which executes a wget and exits: kubectl run busybox -i --rm --image=busybox --restart=Never -- wget http://ingress-nginx-controller/test -O - # This should show the wget request in the tcpdump output...
Code language: Bash (bash)

If you want to talk to ingress using your hosts web browser or command line, you can find the IP-address and port to use like this:

# find the ip address of the docker image which runs the full k8s cluster: docker inspect kind-control-plane | grep IPAddress # In my example it showed: "IPAddress": "" # Now find the port to use: kubectl get svc ingress-nginx-controller # In my case this did show: PORT(S) 80:32246/TCP,443:30823/TCP # So the address to use from the host or command line: curl -v
Code language: Bash (bash)

The above trick works for any kubernetes service which has a NodePort, or LoadBalancer service type. And if you need it for another service, just run a kubectl edit svc on it to change the type to NodePort.

Another option to reach a pod/service inside your Kind cluster is to use port forwarding. Note: this seems to use another route than the normal one, and does NOT show up in the tcpdump if you were testing that example. But for normal tests, it works fine:

# send to the mentioned service, port 80: kubectl port-forward service/ingress-nginx-controller 8123:80
Code language: Bash (bash)

December 18, 2021

Leave a Reply

Your email address will not be published. Required fields are marked *