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 language: Bash (bash)

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

kind create clusterCode 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
# enable EphemeralContainers feature gate
- |
  kind: ClusterConfiguration
    name: config
      "feature-gates": "EphemeralContainers=true"
      "feature-gates": "EphemeralContainers=true"
      "feature-gates": "EphemeralContainers=true"
- |
  kind: InitConfiguration
    name: config
      "feature-gates": "EphemeralContainers=true"
- |
  kind: KubeletConfiguration
    EphemeralContainers: true
- |
  kind: KubeProxyConfiguration
    EphemeralContainers: true
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 clusterCode 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-nginxCode language: Bash (bash)

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

kubectl get nodes

kubectl get pods --all-namespacesCode 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:):

#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 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:80Code language: Bash (bash)

December 18, 2021

Leave a Reply

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