Kategorien
k8s

One of a kind

kubernetes adapter pattern, try it out on Mac.

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.

To run kind nicely, you need to give docker desktop enough memory (see kind web page for details):

memory setting for docker desktop

Basically, I used kind to setup a kubernetes cluster.

# creates a context and sets it, in whatever is you KUBECONFIG file
kind create cluster --name kind-4711 

# check
kubectl config get-contexts
# 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.

adapter container provides prometheus output

The prometheus output visible after portforwarding adapter:9889

main container provides random number

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“