Raspberry Pi Kubernetes Cluster

I figured now the perfect time for me to explore the lightweight Kubernetes project k3s.

The documentation was really solid, plus I found Alex Ortner’s Medium blog post very helpful.

I dusted of a Raspberry Pi 4, and three Raspberry Pi 3’s for this setup.

Logo

I’m still in the mists of my kubernetes journey, but I wanted to share some of the early primitives, and some of the notes I’ve written for myself.

Check all k3s (kubernetes) nodes

sudo kubectl get nodes -o wide
NAME      STATUS                     ROLES                  AGE     VERSION        INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                           KERNEL-VERSION   CONTAINER-RUNTIME
knode1    Ready                      <none>                 4d20h   v1.25.6+k3s1   192.168.1.251   <none>        Raspbian GNU/Linux 11 (bullseye)   5.15.84-v7+      containerd://1.6.15-k3s1
knode2    Ready                      <none>                 4d13h   v1.25.6+k3s1   192.168.1.252   <none>        Raspbian GNU/Linux 11 (bullseye)   5.15.84-v7+      containerd://1.6.15-k3s1
knode3    Ready                      <none>                 4d      v1.25.6+k3s1   192.168.1.147   <none>        Raspbian GNU/Linux 11 (bullseye)   5.15.84-v7+      containerd://1.6.15-k3s1
kmaster   Ready,SchedulingDisabled   control-plane,master   4d20h   v1.25.6+k3s1   192.168.1.250   <none>        Debian GNU/Linux 11 (bullseye)     5.15.84-v8+      containerd://1.6.15-k3s1

Templates for a nginx service

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.16.1
        ports:
        - containerPort: 80
          name: http-web-svc

service.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - name: nginx-port
      protocol: TCP
      port: 80
      targetPort: http-web-svc

ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nginx
  annotations:
    ingress.kubernetes.io/ssl-redirect: "false"
spec:
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80

Deploy templates for a 2 pod nginx replica

sudo kubectl apply -f deployment.yaml
sudo kubectl apply -f service.yaml
sudo kubectl apply -f ingress.yaml

Check the deployment

sudo kubectl get deployment -o wide
NAME               READY   UP-TO-DATE   AVAILABLE   AGE     CONTAINERS   IMAGES                     SELECTOR
nginx-deployment   2/2     2            2           5h9m    nginx        nginx:1.16.1               app=nginx

Check pods

sudo kubectl get pods -o wide'
NAME                                READY   STATUS    RESTARTS   AGE     IP           NODE     NOMINATED NODE   READINESS GATES
nginx-deployment-86646644b7-l5j4x   1/1     Running   0          5h4m    10.42.1.38   knode1   <none>           <none>
nginx-deployment-86646644b7-8s7l8   1/1     Running   0          5h4m    10.42.3.5    knode3   <none>           <none

Check service

sudo kubectl get services -o wide'
NAME            TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)   AGE     SELECTOR
nginx-service   ClusterIP   10.43.79.148   <none>        80/TCP    5h4m    app=nginx

Get dns resolvers ip address

sudo kubectl get service -o wide -A'
NAMESPACE      NAME        TYPE           CLUSTER-IP      EXTERNAL-IP    PORT(S)                      AGE     SELECTOR
kube-system    kube-dns    ClusterIP      10.43.0.10      <none>         53/UDP,53/TCP,9153/TCP       4d20h   k8s-app=kube-dns

Resolve service using k3s dns resolver

dig nginx-service.default.svc.cluster.local @10.43.0.10 +short
10.43.79.148

Access service

curl -I http://10.43.79.148
HTTP/1.1 200 OK
Server: nginx/1.16.1