After reading a nice book about k8s pattern, I was looking for an easy way to run examples. Never been much of a friend of minikube… I came across kind, an easy tool to create kubernetes cluster on my MacPro – as docker containers.
You need docker, or running kind will display a failing docker command:
kind get clusters
ERROR: failed to list clusters: command "docker ps -a --filter label=io.x-k8s.kind.cluster --format '{{.Label "io.x-k8s.kind.cluster"}}'" failed with error: exit status 1
Command Output: request returned Internal Server Error for API route and version http://%
To run kind nicely, you need to give docker desktop enough memory (see kind web page for details):

Basically, I used kind to setup a kubernetes cluster.
# lets check what we have already
kind get clusters
kind get nodes
kubectl config get-contexts --insecure-skip-tls-verify
# docker login ... docker-credential-desktop needed...
# creates a context and sets it, in whatever is you KUBECONFIG file
kind create cluster --name kind-4711
# check
kubectl config get-contexts
# here is what i get when i create a cluster named my3kind
luftichris:.kube christianhofig$kubectl cluster-info --context kind-my3kind
Kubernetes control plane is running at https://127.0.0.1:61310
CoreDNS is running at https://127.0.0.1:61310/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
# context is kind followed by cluster name (kind by default)
# set context
# do things
# cleanup
kind delete cluster --name kind-4711
Then I was able to run the adapter pattern example from here, with a minor variation – not using minishift, not using the clusterIP but a port forward.
kubectl create -f https://k8spatterns.io/Adapter/pod.yml kubectl create -f https://k8spatterns.io/Adapter/service.yml # view the prometheus formatted logs docker login # login succeeded kubectl exec -it random-generator -c main bash cat /logs/random.log # same logs here kubectl exec -it adapter -c main bash cat /logs/random.log # after port forwarding (see below), random generator is here curl localhost:8080 chrisp:tmp sandorm$ curl localhost:8080 2>/dev/null | jq . { "random": -1901296655, "id": "a00fe466-b7ee-4d02-9f1c-0c33bdff3190", "version": "1.0" } chrisp:tmp sandorm$
See https://hub.docker.com/r/k8spatterns/random-generator
Another nice kubernetes visualisation tool, k9s helps to check the results.

After doing the portforwarding for 9889 via k9s, check the random generator and the prometheus formatted log output.

The prometheus output visible after portforwarding adapter:9889

For O’Reilly fans, here is the book I found helpful for understanding k8s pattern:

Some more, how to create a multi node cluster:
chrisp:Kindcluster sandorm$ kind create cluster --config ./kind-sample.config
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.20.2) 🖼
✓ Preparing nodes 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Thanks for using kind! 😊
chrisp:Kindcluster sandorm$ cat kind-sample.config
# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
k config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
/api-crc-testing:6443/developer api-crc-testing:6443 developer/api-crc-testing:6443
c2 c2 rancher-test default
c3 c3 rancher-test kube-system
crc-admin api-crc-testing:6443 kubeadmin default
crc-developer api-crc-testing:6443 developer default
docker-desktop docker-desktop docker-desktop
* kind-kind kind-kind ...
Eine Antwort auf „One of a kind“
[…] example with random generator: One of a kind […]