Kubernetesインストール(シングル) 2022年4月版

https://computingforgeeks.com/install-kubernetes-cluster-on-centos-with-kubeadm/

mmm127: CentOS7 Kubernetes master node
mmm128: CentOS7 Kubernetes worker node


前提:
CPU数=2に増強


※インストール後の作業はmaster nodeから一般ユーザ(test)でおこなう


--(1) masterとworkerの共通作業


yum -y update

useradd test
echo test | passwd --stdin test

visudo

test    ALL=(ALL)  NOPASSWD:    ALL


tee /etc/yum.repos.d/kubernetes.repo<<EOF
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
EOF

yum clean all
yum -y makecache
yum -y install epel-release vim git curl wget kubelet kubeadm kubectl --disableexcludes=kubernetes


kubeadm  version
kubectl version --client

sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
swapoff -a


modprobe overlay
modprobe br_netfilter

tee /etc/sysctl.d/kubernetes.conf<<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

sysctl --system


yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli containerd.io

mkdir /etc/docker
mkdir -p /etc/systemd/system/docker.service.d

tee /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

systemctl daemon-reload 
systemctl restart docker
systemctl enable docker


--(2) master nodeの作成

lsmod | grep br_netfilter
systemctl enable kubelet
kubeadm config images pull

kubeadm init \
--pod-network-cidr=10.0.0.0/16 \
--upload-certs \
--control-plane-endpoint=mmm127.example.com


最後に表示される下記のような出力をコピーペーストして保存。あとでworker nodeで実行する

-- kubeadm join mmm127.example.com:6443 --token r0gwue.82z3zaatg3eeip67 \
--         --discovery-token-ca-cert-hash sha256:1753fdb3fa60asc32cef0e544da279de3f11d27aef18a0ade973c4f05b80fd5d

su - test

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

kubectl cluster-info
kubectl create -f https://docs.projectcalico.org/manifests/tigera-operator.yaml
kubectl create -f https://docs.projectcalico.org/manifests/custom-resources.yaml


export kubever=$(kubectl version | base64 | tr -d '\n')
kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$kubever"

kubectl get nodes
kubectl get pod --all-namespaces
kubectl get nodes -o wide


--(3) worker nodeの作成

kubeadm join mmm127.example.com:6443 --token r0gwue.82z3zaatg3eeip67 \
        --discovery-token-ca-cert-hash sha256:1753fdb3fa60cfc32cef0e544da279de3f11d27aef18a0ade973c4f05b80fd5d


---------------------
master nodeで確認

kubectl get nodes
kubectl get pod --all-namespaces

---------------------