https://brjapon.medium.com/setting-up-ubuntu-20-04-arm-64-under-raspberry-pi-4-970654d12696
https://microk8s.io/docs/registry-built-in
https://microk8s.io/docs/registry-private
https://github.com/docker-library/hello-world
https://www.freecodecamp.org/news/how-to-remove-images-in-docker/
https://gobyexample.com/hello-world
https://linuxconfig.org/how-to-install-go-on-ubuntu-20-04-focal-fossa-linux
https://forums.docker.com/t/docker-private-registry-how-to-list-all-images/21136/2
https://github.com/fraunhoferfokus/deckschrubber
https://collabnix.github.io/kubetools/
Um das Source-Repository nutzen zu können brauchen wir eine Entwicklungsumgebung. Dafür benutzen wir unseren Entwicklungs-Raspbery PI.
Abbildung 8: Gesamtsystem
Dieser Entwicklungs-Raspberry ist ein Raspberry 4 mit 8GB RAM und einer 120 GB SDRAM Karte. Zusätzlich gibt es noch eine 1TB-USB-Platte für all die Backups.
Auf diesem Rechner ist Docker installiert.
alfred@monitoring:~$ docker version
Client:
Version: 20.10.7
API version: 1.41
Go version: go1.13.8
Git commit: 20.10.7-0ubuntu1~20.04.1
Built: Wed Aug 4 22:53:01 2021
OS/Arch: linux/arm64
Context: default
Experimental: true
Server:
Engine:
Version: 20.10.7
API version: 1.41 (minimum version 1.12)
Go version: go1.13.8
Git commit: 20.10.7-0ubuntu1~20.04.1
Built: Wed Aug 4 19:07:47 2021
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.5.2-0ubuntu1~20.04.2
GitCommit:
runc:
https://github.com/docker-library/hello-world Version: 1.0.0~rc95-0ubuntu1~20.04.2
GitCommit:
docker-init:
Version: 0.19.0
GitCommit:
alfred@monitoring:~$
Es gibt sehr viele Anleitungen, wie man Docker installiert. Ich habe dazu folgendes Skript.
#!/bin/bash
############################################################################################
# $Date: 2021-11-22 18:47:00 +0100 (Mo, 22. Nov 2021) $
# $Revision: 1252 $
# $Author: alfred $
# $HeadURL: https://monitoring.slainte.at/svn/slainte/trunk/k8s/k8s_app/portainer/portainer.sh $
# $Id: portainer.sh 1252 2021-11-22 17:47:00Z alfred $
#
# https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04-de
#
# Installieren Docker und Portainer
#
############################################################################################
#shopt -o -s errexit #—Terminates the shell script if a command returns an error code.
shopt -o -s xtrace #—Displays each command before it’s executed.
shopt -o -s nounset #-No Variables without definition
#
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
sudo apt update
apt-cache policy docker-ce
sudo apt install docker-ce
sudo usermod -aG docker ${USER}
#
docker volume create portainer_data
docker run -d -p 8000:8000 -p 9443:9443 --name portainer \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /portainer_data:/data \
portainer/portainer-ce:latest
docker ps
docker run -d -p 9001:9001 --name portainer_agent \
--restart=always \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker/volumes:/var/lib/docker/volumes \
portainer/agent:latest
Damit gibt es dann auch den Portainer, der recht praktisch ist, um die lokale Dockerinstallation zu steuern.
Abbildung 9: Portainer
Wir müssen das Repository das sich am Kubernetes Cluster befindet in die Konfiguration am Entwicklungsrechner eintragen.
alfred@monitoring:~/go$ cat /etc/hosts
127.0.0.1 localhost
127.0.0.1 monitoring
127.0.0.1 monitoring.slainte.at
192.168.0.213 docker.registry
192.168.0.201 pc1
192.168.0.202 pc2
192.168.0.203 pc3
192.168.0.204 pc4
192.168.0.205 pc5
alfred@monitoring:~/go$ sudo cat /etc/docker/daemon.json
{
"insecure-registries" : ["docker.registry:5000"]
}
Die Registry ist als Loadbalancer-Service ausfallsicher. Die Storage ist in einem persistant volume, somit funktioniert das auch von überall im Cluster.
Nun können wir versuchen ein hello world zu erzeugen.
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
Dieser Programmteil ist in GO geschrieben. Go wird wie folgt installiert.
alfred@monitoring:~$ sudo apt install golang
alfred@monitoring:~$ go version
go version go1.13.8 linux/arm64
alfred@monitoring:~$
Dann kann man das go Programm testen und builden.
alfred@monitoring:~$ mkdir go
alfred@monitoring:~$ cd go
alfred@monitoring:~/go$ nano hello-world.go
alfred@monitoring:~/go$ go run hello-world.go
hello world
alfred@monitoring:~/go$ go build hello-world.go
alfred@monitoring:~/go$ ls -lisa
total 1936
4688691 4 drwxrwxr-x 2 alfred alfred 4096 Sep 30 11:26 .
1140881 4 drwxr-xr-x 21 alfred alfred 4096 Sep 30 11:25 ..
127267 1924 -rwxrwxr-x 1 alfred alfred 2097605 Sep 30 11:26 hello-world
4688693 4 -rw-rw-r-- 1 alfred alfred 75 Sep 30 11:25 hello-world.go
alfred@monitoring:~/go$ ./hello-world
hello world
alfred@monitoring:~/go$
Jetzt haben wir das go-Programm, und müssen es in einen Docker-Container packen.
alfred@monitoring:~/go$ docker rmi $(docker images -q) # Löscht alle vorhandenen Images im lokalen Repository
Um einen Container zu erzeugen, brauchen wir ein dockerfile.
alfred@monitoring:~/dev/hello-world$ cat dockerfile
# syntax=docker/dockerfile:1
# Alpine is chosen for its small footprint
# compared to Ubuntu
FROM golang:1.16-alpine
WORKDIR /app
LABEL maintainer="microk8s.raspberry@slainte.at"
COPY go.mod ./
COPY *.go ./
RUN go build -o /hallo
EXPOSE 80
CMD ["/hallo"]
alfred@monitoring:~/dev/hello-world$
Nun bauen wir den Container.
alfred@monitoring:~/dev/hello-world$ docker build . -t docker.registry:5000/hello-world:20211003
Sending build context to Docker daemon 9.216kB
Step 1/8 : FROM golang:1.16-alpine
1.16-alpine: Pulling from library/golang
be307f383ecc: Already exists
e31131f141ae: Pull complete
7f3ae2225eeb: Pull complete
27b4cf6759f9: Pull complete
05c56ed0aaf5: Pull complete
Digest: sha256:45412fe3f5016509fc448b83faefc34e6f9e9bcc8ca1db1c54505d5528264e16
Status: Downloaded newer image for golang:1.16-alpine
---> bebfc96a903d
Step 2/8 : WORKDIR /app
---> Running in c81df142320d
Removing intermediate container c81df142320d
---> a81936939cb7
Step 3/8 : LABEL maintainer="microk8s.raspberry@slainte.at"
---> Running in 88c7acfdf90e
Removing intermediate container 88c7acfdf90e
---> b023746a02d8
Step 4/8 : COPY go.mod ./
---> 599501f1547a
Step 5/8 : COPY *.go ./
---> 9f60a66c2ac0
Step 6/8 : RUN go build -o /hallo
---> Running in 03fd6b04a839
Читать дальше