Learn Kk8s-- build k8s cluster

  The best way to learn k8s is a k8s build their own cluster, and the actual operation. According to the official course, it is not complicated, but due to network problems, a lot of software can not download and mirroring, so the installation process is quite troublesome.

  K8s do not need to learn a clustered environment, the personal computer can build a stand-alone cluster to learn. Following is a brief procedure under skipped relatively simple steps, the next focus on that need to pay attention

First, install the virtual machine and linux systems

  Virtual machines can use hyper-v, virtualbox, and vmware. I use VirtualBox 6.1.0 version, Download is https://www.virtualbox.org/wiki/Downloads .

  System is used CentOS-7-x86_64-Minimal- 1908. To learn if the proposed use Minimal, download and install quickly. Download is  http://isoredirect.centos.org/centos/7/isos/x86_64/ , select a faster download mirror address.

  Installation tutorial, online a lot, can not say here. Need advice where is 1, the installation language selection Chinese. 2, select the minimum software installation, disable kdump; configure network connections

  Note: 1, the number of the virtual machine configuration is set to 2 or more CPU

     2, the firewall will bring some problems k8s cluster, where just learning, you can turn off the firewall directly.

     3, close Swap. Performing swapoff -a temporarily closed, edit / etc / fstab, comment out the line that can contain the swap, can be permanently closed after restarting

  

systemctl stop firewalld & systemctl disable firewalld

 

Second, the installation docker

  Referring first official document

  https://docs.docker.com/install/linux/docker-ce/centos/#prerequisites

  https://kubernetes.io/docs/setup/production-environment/container-runtimes/

  

The Install Docker CE # 
## the Set up at The Repository 
### required the Install Packages Standard Package. 
Yum  install  yum -utils-Device-Mapper persistent- the Data lvm2 

### Docker the Add Repository. 
### Note that Ali cloud into the address
yum - Manager --add--config the repo \ https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo . Docker the Install the CE ## yum Update && yum the install \ containerd.io \ Docker - ce \ Docker -ce-cli ## the Create / etc / Docker Directory. mkdir / etc / Docker # Setup daemon. cat > /etc/docker/daemon.json <<EOF { "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "storage-opts": [ "overlay2.override_kernel_check=true" ] } EOF mkdir -p /etc/systemd/system/docker.service.d # Restart Docker systemctl daemon-reload systemctl restart docker

echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables

  Set boot

systemctl start docker & systemctl enable docker

  Verifying Successful Installation

docker run hello-world

  The results are as follows

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 

Third, the installation Kubernetes

  Official documents https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

  Note: You need to change the country's image address

## configuration kubernetes.repo, Ali cloud into a note address, or hold off. 
CAT
<< the EOF> / etc / yum .repos.d / kubernetes.repo [Kubernetes] name = Kubernetes BaseURL = http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 Enabled = . 1 gpgcheck = . 1 repo_gpgcheck = . 1 gpgkey = http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key. gpg
EOF

# Set SELinux in permissive mode (effectively disabling it)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable --now kubelet

  Start kubelet

systemctl enable kubelet && systemctl start kubelet

 

Fourth, the stand-alone cluster configuration K8S

  As used herein Calico plan to deploy single cluster k8s

  The official document: https://docs.projectcalico.org/v3.11/getting-started/kubernetes/

  The initial environmental change, and install the downloaded image k8s

The init = pod-network-cidr kubeadm 192.168 . 0.0 / 16

  Note that ip address changes according to the actual situation

  Since this step requires a docker download k8s mirror, not domestic agent is downloaded, then basically not down. So here to be wrong, cause of the error is mirrored pull failure. Receive an error message similar to the following

  

[ERROR ImagePull]: failed to pull image k8s.gcr.io/kube-apiserver:v1.17.0: output: Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

, error: exit status 1

  Failure information given pull mirror address failure. On github someone has already downloaded all of the image and upload it to the national address, you can download from that.

  github Address: https://github.com/anjia0532/gcr.io_mirror

  Mirroring address translation rules

  

gcr.io/namespace/image_name:image_tag 
#eq
gcr.azk8s.cn/namespace/image_name:image_tag 

# special
k8s.gcr.io/{image}/{tag} <==> gcr.io/google-containers/{image}/{tag} <==> gcr.azk8s.cn/namespace/image_name:image_tag 

  Such as described above, then the initial address of the failed download image k8s.gcr.io/kube-apiserver:v1.17.0.

. k8s.gcr.io/kube-apiserver:v1 17.0 
is converted into 
gcr.azk8s.cn / Google-Containers / Kube-apiserver:. V1 17.0

  Download image

docker pull gcr.azk8s.cn/google-containers/kube-apiserver:v1.17.0

  Because, kubeadm init pull mirror address is the official address, so we need to hit the corresponding tag

docker tag gcr.azk8s.cn/google-containers/kube-apiserver:v1.17.0  k8s.gcr.io/kube-apiserver:v1.17.0

 

  In the same way to complete the download all images. Then perform the initialization again, and if that fails, you can perform kubeadm reset

The init = pod-network-cidr kubeadm 192.168 . 0.0 / 16

  Continue

  

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

  Installation Calico

kubectl apply -f https://docs.projectcalico.org/v3.11/manifests/calico.yaml

  This step also need to download the appropriate calico mirror may also download fails, you can go above yaml file, find the image you want, then download the search mode, can not say here.

  Verify successful

  

watch kubectl get pods --all-namespaces

  The following results on that success

  

NAMESPACE    NAME                                       READY  STATUS   RESTARTS  AGE
kube-system  calico-kube-controllers-6ff88bf6d4-tgtzb   1/1    Running  0         2m45s
kube-system  calico-node-24h85                          1/1    Running  0         2m43s
kube-system  coredns-846jhw23g9-9af73                   1/1    Running  0         4m5s
kube-system  coredns-846jhw23g9-hmswk                   1/1    Running  0         4m5s
kube-system  etcd-jbaker-1                              1/1    Running  0         6m22s
kube-system  kube-apiserver-jbaker-1                    1/1    Running  0         6m12s
kube-system  kube-controller-manager-jbaker-1           1/1    Running  0         6m16s
kube-system  kube-proxy-8fzp2                           1/1    Running  0         5m16s
kube-system  kube-scheduler-jbaker-1                    1/1    Running  0         5m41s

  If calico-node appears ErrorImagePull and other state would indicate that the image is not downloaded successfully, so you need to manually domestic mirrored address to download, the name and version numbers https://docs.projectcalico.org/v3.11/manifests/calico. yaml

  Configure the master node to node work

kubectl taint nodes --all node-role.kubernetes.io/master-

  The results are as follows

node/<your-hostname> untainted

  The last run

  

kubectl get nodes -o wide

  Type the following results appear to indicate success

NAME              STATUS   ROLES    AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION    CONTAINER-RUNTIME
<your-hostname>   Ready    master   52m   v1.12.2   10.128.0.28   <none>        Ubuntu 18.04.1 LTS   4.15.0-1023-gcp   docker://18.6.1

 

  

Guess you like

Origin www.cnblogs.com/lilinwei340/p/12099217.html