Toggle navigation
Home
安装部署
Archives
Tags
MicroK8s Deployment
2021-08-06 04:50:08
61
0
0
louyj
MicroK8s is the smallest, fastest, fully-conformant Kubernetes that tracks upstream releases and makes clustering trivial. MicroK8s is great for offline development, prototyping, and testing. #Install MicroK8s ##Requirements - Operating system which supports `snapd` - At least 20G of disk space and 4G of memory are recommended - An internet connection For Centos7 service firewall stop && systemctl disable firewalld yum install epel-release yum install snapd systemctl enable --now snapd.socket sudo ln -s /var/lib/snapd/snap /snap ##Install MicroK8s MicroK8s will install a minimal, lightweight Kubernetes you can run and use on practically any machine. It can be installed with a snap: snap install microk8s --classic --channel=1.21/stable snap install microk8s --classic --channel=1.19/stable #from 1.21 to 1.19 snap refresh --classic --channel=1.19/stable microk8s All the currently available channels are shown if you run snap info microk8s ##Join the group MicroK8s creates a group to enable seamless usage of commands which require admin privilege. To add your current user to the group and gain access to the .kube caching directory, run the following two commands sudo usermod -a -G microk8s $USER sudo chown -f -R $USER ~/.kube ##Check the status MicroK8s has a built-in command to display its status. During installation you can use the `--wait-ready` flag to wait for the Kubernetes services to initialise microk8s status --wait-ready ##Using proxy for images To let MicroK8s use a proxy we need to enter the proxy details in `/var/snap/microk8s/current/args/containerd-env` The containerd-env file holds the environment variables containerd runs with. Setting the HTTPS_PROXY to your proxy endpoint enables containerd to fetch conatiner images from the web. HTTPS_PROXY=http://192.168.0.201:6666 HTTP_PROXY=http://192.168.0.201:6666 NO_PROXY=10.1.0.0/16,10.152.183.0/24 For the changes to take effect we need to restart MicroK8s: sudo snap restart microk8s ##Using private registry For MicroK8s version 1.23 or newer MicroK8s 1.23 and newer versions use separate hosts.toml files for each image registry. For registry http://10.141.241.175:32000, this would be at /var/snap/microk8s/current/args/certs.d/10.141.241.175:32000/hosts.toml. First, create the directory if it does not exist: ``` sudo mkdir -p /var/snap/microk8s/current/args/certs.d/docker.louyj.top sudo touch /var/snap/microk8s/current/args/certs.d/docker.louyj.top/hosts.toml ``` Then, edit the file we just created and make sure the contents are as follows: ``` # /var/snap/microk8s/current/args/certs.d/docker.louyj.top/hosts.toml server = "https://docker.louyj.top" [host."https://docker.louyj.top"] capabilities = ["pull", "resolve"] ``` It is possible to configure default credentials in the configuration of containerd, so that they are used automatically when pulling images from your private registry, without users having to specify an image pull secret manually for each container. To do this, you have to edit `/var/snap/microk8s/current/args/containerd-template.toml`. If the private registry at 10.141.241.175:32000 needs authentication with username my-secret-user and password my-safe-password, add the following section (the configuration is in TOML format, so indentation does not matter): ``` # containerd-template.toml #sandbox_image = "registry.k8s.io/pause:3.7" sandbox_image = "docker.louyj.top/pause:3.7" [plugins."io.containerd.grpc.v1.cri".registry.configs."docker.louyj.top".auth] username = "rep_docker" password = "@WSX1qaz" ``` Restart MicroK8s to have the new configuration loaded: ``` microk8s stop microk8s start ``` ##Access Kubernetes MicroK8s bundles its own version of kubectl for accessing Kubernetes. Use it to run commands to monitor and control your Kubernetes. For example, to view your node: microk8s kubectl get nodes MicroK8s uses a namespaced kubectl command to prevent conflicts with any existing installs of kubectl. If you don’t have an existing install, it is easier to add an alias alias kubectl='microk8s kubectl' ##Working with kubectl If you’d prefer to use your host’s kubectl command, running the following command will output the kubeconfig file from MicroK8s. microk8s config If you have not already configured kubectl on the host, you can just open a terminal and generate the required config : ``` cd $HOME mkdir .kube cd .kube microk8s config > config ``` ##Use add-ons MicroK8s uses the minimum of components for a pure, lightweight Kubernetes. However, plenty of extra features are available with a few keystrokes using “add-ons” - pre-packaged components that will provide extra capabilities for your Kubernetes, from simple DNS management to machine learning with Kubeflow! To start it is recommended to add DNS management to facilitate communication between services. For applications which need storage, the ‘storage’ add-on provides directory space on the host. These are easy to set up export LC_ALL="en_US.UTF-8" export LC_CTYPE="en_US.UTF-8" microk8s enable dns storage microk8s enable dashboard microk8s enable ingress See the full list of addons: https://microk8s.io/docs/addons#heading--list ###Configure DNS ``` kubectl -n kube-system edit configmap/coredns forward . 8.8.8.8 8.8.4.4 forward . 172.21.4.4 8.8.8.8 8.8.4.4 ``` ##Starting and Stopping MicroK8s MicroK8s will continue running until you decide to stop it. microk8s stop You can start again any time by running microk8s start Note that if you leave MicroK8s running, it will automatically restart after a reboot. If you don’t want this to happen, simply remember to run microk8s stop before you power down. ##Adding a node To create a cluster out of two or more already-running MicroK8s instances, use the microk8s add-node command. The MicroK8s instance on which this command is run will be the master of the cluster and will host the Kubernetes control plane microk8s add-node This will return some joining instructions, such as: ``` Join node with: microk8s join ip-172-31-20-243:25000/DDOkUupkmaBezNnMheTBqFYHLWINGDbf If the node you are adding is not reachable through the default interface you can use one of the following: microk8s join 10.1.84.0:25000/DDOkUupkmaBezNnMheTBqFYHLWINGDbf microk8s join 10.22.254.77:25000/DDOkUupkmaBezNnMheTBqFYHLWINGDbf ``` ##Removing a node First, on the node you want to remove, run microk8s leave. MicroK8s on the departing node will restart its own control plane and resume operations as a full single node cluster: microk8s leave To complete the node removal, call microk8s remove-node from the remaining nodes to indicate that the departing (unreachable now) node should be removed permanently: microk8s remove-node 10.22.254.79 ##High Availability From the 1.19 release of MicroK8s, HA is enabled by default. If your cluster consists of three or more nodes, the datastore will be replicated across the nodes and it will be resilient to a single failure The microk8s status now includes information about the HA state. For example: ``` microk8s is running high-availability: yes datastore master nodes: 10.128.63.86:19001 10.128.63.166:19001 10.128.63.43:19001 datastore standby nodes: none ``` ##Pull Docker Image microk8s.ctr images pull docker.io/library/nextcloud:22 ##Reset ``` snap remove microk8s --purge snap install microk8s --classic --channel=1.27/stable ```
Pre:
Esxi Installation
Next:
shadows
0
likes
61
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Submit
Sign in
to leave a comment.
No Leanote account?
Sign up now.
0
comments
More...
Table of content
No Leanote account? Sign up now.