In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to build a local kubernets cluster in virtualBox. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Virtual machine preparation 1.1 download the image of centos7
Note that centos8 does not support kubeadm, blood and tears lessons. Also do not mini will not be able to use the interface. Http://mirrors.aliyun.com/centos/7/isos/x86_64/
Do not use minimized installation, otherwise it is not convenient to install the enhancements next.
Systemctl stop firewalld & & systemctl disable firewalld1.2 turns off sawp memory space
When installing the K8S cluster, the Swap memory swapping mechanism of Linux must be turned off, otherwise the performance and stability will be affected because of memory swapping. Here, we can set it up in advance:
Executing swapoff-a can shut down temporarily, but it will resume after system restart.
Edit / etc/fstab, comment out the line containing swap and permanently close it. You can comment out the line by executing the following command:
Sed-I'/ swap / s / ^ / # /'/ etc/fstab1.3 close SeLinux
Execute setenforce 0 to temporarily shut down
Permanently close the file settings that need to be modified / etc/sysconfig/selinux
Sed-I'/ SELINUX=e\ | SELINUX=p\ | SELINUX=d/c\ SELINUX=disabled' / etc/sysconfig/selinux1.4 configure bridging mode
The bridging mode is equivalent to assuming a virtual network card and adding the virtual machine to the network card area where the host is located, so the interface name is the name of the host network card.
Can be set on the network and internet
Then check the network card that is in use now.
By shutting down the network card, it is found that ens8 is actually doing the bridge and communicating with the outside world.
One of the centos network card configuration file directory: cd / etc/sysconfig/network-scripts/, we need to change is vi / etc/sysconfig/network-scripts/ifcfg-enp0s8, enter the following content. (irrelevant after testing)
BOOTPROTO= "static" IPADDR=192.168.0.50GATEWAY=192.168.0.1DNS1=192.168.0.1DNS2=8.8.8.8NETMASK=255.255.255.0
The host can ping the virtual machine, but the virtual machine cannot ping the host.
1.5 install enhancements
Refer to my last blog: https://www.yisu.com/article/234291.htm
1.6 XSHELL connection SSH
To prevent the need for x11, you need to add a modified Defaults env_keep= "DISPLAY XAUTHORITY" to vi / etc/sudoers
two。 Install docker2.1 to uninstall the old docker version
First, refer to the steps on the official website, https://docs.docker.com/engine/install/centos/#prerequisites.
Uninstall the old version first:
Sudo yum remove docker\ docker-client\ docker-client-latest\ docker-common\ docker-latest\ docker-latest-logrotate\ docker-logrotate\ docker-engine2.2 configure Ali's image repository sudo yum install-y yum-utilsyum-config -manager\-- add-repo\ http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo2.3 install the latest version of Docker Engine and containerd
In this step, you may encounter problems that conflict with podman. Podman is a packaging tool used by redhat to replace docker, so just remove it:
Yum erase podman buildahsudo yum install docker-ce docker-ce-cli containerd.io
2.4 launch docker and test it with helloWord. If successful, you can see the prompt for correct installation in the result:
Sudo systemctl start dockersudo docker run hello-world
The design starts and removes the container after testing.
Systemctl enable docker2.5 avoids conflicts with kubelet
Docker info | grep cgroup view, if the Cgroup Driver used by docker is cgroupfs. It may conflict with kubelet and need to be changed to a consistent systemd.
First vi / etc/docker/daemon.json, add the following code to the file, and restart docker to systemctl restart docker
{"exec-opts": ["native.cgroupdriver=systemd"]} 3. Install kubernetes
We use the kubeadm tool provided by the official kubernetes to install the kubernetes cluster. The official documentation can be found at: https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/
3.2Configuring yum feeds for kubernetes
Aliyun's image warehouse is used here. Tencent's image warehouse has been used before and an error of 404 has been reported. In fact, it should be the source error of the image warehouse.
Errors during downloading metadata for repository 'kubernetes':
-Status code: 404 for https://mirrors.cloud.tencent.com/kubernetes/yum/repos/kubernetes-el7-x86_64/repodata/repomd.xml.asc (IP: 120.196.204.237)
-Status code: 404 for https://mirrors.cloud.tencent.com/kubernetes/yum/doc/yum-key.gpg (IP: 120.196.204.75)
Error: failed to obtain GPG key for repository 'kubernetes': Status code: 404 for https://mirrors.cloud.tencent.com/kubernetes/yum/doc/yum-key.gpg (IP: 120.196.204.75)
In addition, the blogger's reference to Ali Yun's warehouse also failed, and the latest one found this:
# configure k8s Ali cloud source cat kubeadm.conf for easy modification and viewing. Then it is mainly changed to images-repository, and if verified, kubeadm config images pull-- config kubeadm.conf
If you install the wrong version, you need to cancel the init before you can redeploy it. This is done through kubeadm reset. The reset process does not reset or clear the iptables rule or IPVS table. You can see the prompt after the reset, but we can just initialize the direct reset.
Configure kubeconfig:
To start using your cluster, you need to run the following as a regular user: mkdir-p $HOME/.kube sudo cp-I / etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id-u): $(id-g) $HOME/.kube/configAlternatively, if you are the root user, you can run: export KUBECONFIG=/etc/kubernetes/admin.conf3.7 Let child nodes join 3.71 child nodes
All you have to do is run the following command on the child node, which is prompted by init above:
Kubeadm join k8smaster.com:6443-token pdas2m.fkgn8q7mz5u96jm6-discovery-token-ca-cert-hash sha256:6fd9b1bf2d593d2d4f550cd9f1f596865f117fef462db42860228311c2712b8b
If there is no record, you can view it through kubeadm token list. If there is no output indicating that the previous token has expired, generate a new kubeadm token create-- print-join-command directly. The default validity period is 24 hours. If you want to take a long time, you can combine the-ttl parameter. Set it to 0 and do not expire.
Kubeadm join k8smaster.com:6443-token pdas2m.fkgn8q7mz5u96jm6-discovery-token-ca-cert-hash sha256:6fd9b1bf2d593d2d4f550cd9f1f596865f117fef462db42860228311c2712b8b
If there is output, such as the following, it is found that only token does not have CA:
You also need to decrypt to obtain a certificate: openssl x509-pubkey-in / etc/kubernetes/pki/ca.crt | openssl rsa-pubin-outform der 2 > / dev/null | openssl dgst-sha256-hex | sed's / ^. * / /'
So the result is the value of 6fd9b1bf2d593d2d4f550cd9f1f596865f117fef462db42860228311c2712b8b, that is,-discovery-token-ca-cert-hash sha256:.
If an error is reported:
Error execution phase preflight: couldn't validate the identity of the
API Server: could not find a JWS signature in the cluster-info
ConfigMap for token ID "ecqb8f"
Because the token has expired, just generate a new one
3.72 correct use of kubelet for child nodes
Unable to use kubelet get nodes properly. The error is as follows:
The connection to the server localhost:8080 was refused-did you
Specify the right host or port?
Use root users first, but it still doesn't work.
Mkdir $HOME/.kube/cp-I / etc/kubernets/kubelet.conf $HOME/.kube/configchown 1000 HOME/.kube/cp 1000$ HOME/.kube/config3.8 configuration flannel# download flannel.yaml https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlkubectl apply-f kube-flannel.yml
Image: quay.io/coreos/flannel:v0.11.0-amd64 may pull very slowly. You can download the exported image package in advance and execute docker load on the node to complete the image import (.docker) or docker import (.tar).
When flannel gets up, cosedns gets up, too.
Thank you for reading! This is the end of the article on "how to build a local kubernets cluster in virtualBox". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.