Use microk8s to make a kubernetes environment in Linux

注意:从 github上来看 microk8s的状态不好,有100+的issues,且其build状态为failed。暂停关于microk8s方面的任务。

The microk8s is a good entry level tool to help us get started with kubernetes.

To install it, refer to
https://microk8s.io/docs/ .

After that, when we want to access the api server, we'll need the default username and password. It can be found in /var/snap/microk8s/current/credentials/basic_auth.csv

After that, we have a single node cluster available to play with. A few kube addons are recommended to install.

Kube Addons

We'll use a local directory as a storage class for storage service for our stateful deployments.

We'll use a private registry so that it will be faster for kubeletes to pull images on demand.

Storage addon

To enable,

microk8s.enable storage

Registry

To enable,

microk8s.enable registry

The registry service is a nodeType service, exposing at 32000. However, when I tried to access it, I got TLS timeout issue. I'll have to find out how to inspect and trouble shoot it. After a search (https://github.com/ubuntu/microk8s/issues/196 ), it is due to something wrong with IPv6. So we'll have to disable IPv6 of the system, or use an explict name that resolves to an IPv4 or an IPv4 address when tagging the image repository, as below:

sudo docker pull busybox
sudo docker tag busybox 127.0.0.1:32000/busybox
sudo docker push 127.0.0.1:32000/busybox

To use this image from the private registry,

With a manifest to deploy,,, todo.

接下来,我们会发现,在初始化时无法获取一些默认的镜像。其表现为,describe中可用观察到的异常events;其解决办法有两种,

一是根据github上kubernetes的源代码进行image的构建,然后修改配置文件 (默认配置请参考
https://github.com/ubuntu/microk8s/blob/master/microk8s-resources/default-args/containerd-template.toml ),将拉取镜像的配置进行更新 (这种做法能否凑效,还要看实现情况。目前看来http请求方式的private mirror有问题)

sudo vi /var/snap/microk8s/current/args/containerd-template.toml
sudo systemctl restart snap.microk8s.daemon-containerd.service

二是采用一个proxy来获取k8s.io上的镜像。设置http proxy的位置是在文件 /var/snap/microk8s/current/args/containerd-env 中。修改以后,要记得重启相应的服务

 sudo systemctl restart snap.microk8s.daemon-containerd.service