DevOps Buzz
Search…
Bash / Shell
Bitbucket
Distros
Elasticsearch
General
Guidelines / Standards
microk8s
Prometheus
RabbitMQ
VirtualBox
Cheat Sheet
Microk8s tips and tricks

Install

Latest

1
snap install microk8s --classic
Copied!

Specific version

1
snap install microk8s --classic --channel=1.17/stable
Copied!

Set group

1
sudo usermod -a -G microk8s $USER
Copied!
Logout from your workstation session and login again.

Useful commands

Get kubeconfig

1
microk8s.config > $HOME/.kube/config
Copied!

Reset cluster

1
microk8s reset --destroy-storage
Copied!

References

Built-in Registry

Push

Pushing to this insecure registry may fail in some versions of Docker unless the daemon is explicitly configured to trust this registry. To address this we need to edit /etc/docker/daemon.json and add:
/etc/docker/daemon.json
1
{
2
"insecure-registries" : ["localhost:32000"]
3
}
Copied!
Then restart docker.
1
sudo systemctl restart docker
Copied!
Enable registry, build and push image.
1
microk8s enable registry #20Gi registry
2
#microk8s enable registry:size=40Gi
3
4
# Build image
5
docker build . -t localhost:32000/myimage:registry
6
7
# Or tag an existing image
8
#docker tag 1fe3d8f47868 localhost:32000/myimage:registry
9
10
docker push localhost:32000/myimage:registry
Copied!
Deploy it.
1
apiVersion: apps/v1
2
kind: Deployment
3
metadata:
4
name: myapp
5
namespace: myapp
6
labels:
7
app: myapp
8
spec:
9
selector:
10
matchLabels:
11
app: myapp
12
template:
13
metadata:
14
labels:
15
app: myapp
16
spec:
17
containers:
18
- name: myapp
19
image: localhost:32000/myimage:registry
20
imagePullPolicy: Always
21
ports:
22
- containerPort: 8000
Copied!

Remove

Run on your workstation:
1
registry=localhost:32000
2
repositories=$(curl ${registry}/v2/_catalog)
3
for repo in $(echo "${repositories}" | jq -r '.repositories[]'); do
4
echo $repo
5
tags=$(curl -sSL "http://${registry}/v2/${repo}/tags/list" | jq -r '.tags[]')
6
for tag in $tags; do
7
echo $tag
8
curl -v -sSL -X DELETE "http://${registry}/v2/${repo}/manifests/$(
9
curl -sSL -I \
10
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
11
"http://${registry}/v2/${repo}/manifests/$tag" \
12
| awk '$1 == "Docker-Content-Digest:" { print $2 }' \
13
| tr -d #x27;\r' \
14
)"
15
done
16
done
Copied!
Then run:
1
registry_pod=$(kubectl --namespace="container-registry" get pods --template '{{range .items}}{{.metadata.name}}{{"\n"}}{{end}}')
2
kubectl exec --namespace="container-registry" $registry_pod /bin/registry garbage-collect /etc/docker/registry/config.yml
Copied!

Local private registry

Allow insecure registry:
/etc/docker/daemon.json
1
{
2
"insecure-registries" : ["172.17.0.1:5001"]
3
}
4
Copied!
Restart docker.
1
sudo systemctl restart docker
Copied!
Stop microk8s, backup and edit config file.
1
microk8s stop
2
sudo cp /var/snap/microk8s/current/args/containerd-template.toml /var/snap/microk8s/current/args/containerd-template.toml-BKP
3
nano /var/snap/microk8s/current/args/containerd-template.toml
Copied!
Add the following section.
1
...
2
[plugins."io.containerd.grpc.v1.cri".registry]
3
...
4
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]
5
...
6
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."172.17.0.1:5001"]
7
endpoint = ["http://172.17.0.1:5001"]
Copied!
Start microk8s.
1
microk8s start
Copied!
Start local registry.
1
docker run -it --rm \
2
-e REGISTRY_HTTP_ADDR=0.0.0.0:5001 \
3
-p 5001:5001 \
4
--name local-registry \
5
registry:2
Copied!
Tag and push image.
1
docker tag ubuntu:18.04 172.17.0.1:5001/my-ubuntu:0.0.1
2
docker push 172.17.0.1:5001/my-ubuntu:0.0.1
3
curl 172.17.0.1:5001/v2/_catalog
Copied!
Test it.
1
microk8s kubectl run -it --rm tmp --image=172.17.0.1:5001/my-ubuntu:0.0.1
Copied!

References