test setup

Hostnames

  • control-plane
  • worker-1
  • worker-2
> sudo vim /etc/hosts
---
192.168.254.20 control-plane
192.168.254.21 worker-1
192.168.254.22 worker-2
---

> sudo systemctl disable firewalld
#> sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
> sudo sed -i '/swap/d' /etc/fstab
> sudo cat << EOF | sudo tee /etc/modules-load.d/containerd.conf
overlay
br_netfilter
EOF
> sudo cat << EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

> sudo systemctl stop firewalld
#> sudo setenforce Permissive
> sudo modprobe overlay
> sudo modprobe br_netfilter
> sudo sysctl --system
> sudo swapoff -a

> sudo yum install iproute-tc chrony -y

> sudo yum install yum-utils -y
> sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
#> sudo yum update -y
> sudo yum install containerd.io -y

> sudo mkdir -p /etc/containerd
> sudo containerd config default | sudo tee /etc/containerd/config.toml

> sudo vim /etc/containerd/config.toml
---
below:
          [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
add:
            SystemdCgroup = true
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
  SystemdCgroup = true
---

> sudo systemctl enable containerd
> sudo systemctl start containerd
> sudo systemctl status containerd

> sudo cat << EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF

#> sudo yum update -y
> sudo yum install kubelet-1.21.0-0 kubeadm-1.21.0-0 kubectl-1.21.0-0 -y

# on master
> sudo systemctl enable kubelet.service
> sudo systemctl start kubelet.service

> sudo yum install yum-plugin-versionlock -y
> sudo yum versionlock kubelet kubeadm kubectl

> sudo kubeadm config print init-defaults | tee ClusterConfiguration.yaml

> sudo sed -i '/name/d' ClusterConfiguration.yaml
# change ip
> sudo sed -i 's/ advertiseAddress: 1.2.3.4/ advertiseAddress: 192.168.254.20/' ClusterConfiguration.yaml
> sudo sed -i 's/ criSocket: \/var\/run\/dockershim\.sock/ criSocket: \/run\/containerd\/containerd\.sock/' ClusterConfiguration.yaml

> sudo cat << EOF | cat >> ClusterConfiguration.yaml
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
EOF

# on control plane
> sudo systemctl restart containerd
> sudo kubeadm init --config=ClusterConfiguration.yaml --cri-socket /run/containerd/containerd.sock
#> kubeadm init --apiserver-advertise-address=10.128.1.3 --apiserver-cert-extra-sans=10.128.1.3 --node-name k8smaster --pod-network-cidr=192.168.0.0/16
--
kubeadm join 10.0.0.70:6443 --token abcdef.0123456789abcdef \
	--discovery-token-ca-cert-hash sha256:c750a16eddfe10c59a821a5dd61555c952d82a89956783e66e2399e4e233324d


> mkdir -p /home/kube/.kube
> sudo cp -i /etc/kubernetes/admin.conf /home/kube/.kube/config
> sudo chown kube:kube /home/kube/.kube/config

> kubectl get nodes
# callico 
> kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
# waeve
> export kubever=$(kubectl version | base64 | tr -d '\n')
> kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"


> kubectl get nodes

> kubeadm token create --print-join-command

# on worker - kubelet s
> sudo kubeadm join 192.168.254.20:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:e60463ed4aa5d49f0f41460c6904f992f0e53f1921f81dc88a80131a9be273c0

> kubectl get pods -A

kubeadm reset cleanup-node to reset a node

debug: /var/lib/kubelet/config.yaml #cgroupDriver: systemd cgroupDriver: cgroupfs

sudo yum remove -y kubelet sudo yum install -y kubelet sudo systemctl enable kubelet.service sudo systemctl start kubelet.service

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

network: stat /var/lib/calico/nodename: no such file or directory: check that the calico/node container is running and has mounted /var/lib/calico/