GCP(Centos7) Kubernetes 설치

Published: by Creative Commons Licence

준비사항

저는 GCP 무료평가판 계정으로 실습을 진행했습니다.
클러스터 구성을 위해 Master Node 1개 Work Node 2개로 총 세 개의 인스턴스를 생성했습니다.

OS : CentOS 7.9
CPU : 2개
Memory : 4GB

1.Master Node, Work Node 공통

  • Docker 설치
$ 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 docker-ce
$ systemctl start docker && systemctl enable docker
  • 방화벽 비활성화
$ systemctl stop firewalld
$ systemctl disable firewalld
$ systemctl status firewalld
  • iptable 설정
$ cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

$ sysctl --system
  • SELinux 설정변경(enforce > permissive)
$ setenforce 0
$ sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
  • SWAP 관련 주석 - 나는 아래 내용이 없어서 주석을 하지 않았다.
$ swapoff -a
$ vim /etc/fstab
# LABEL=SWAP-xvdb1 swap swap defaults    0 0

$ reboot
  • Kubernetes Repo 추가 및 kubelet, kubeadm, kubectl 설치
$ 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

$ yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
$ systemctl enable kubelet && systemctl start kubelet

2. Master Node

  • 쿠버네티스 초기화(CNI-calico)
$ kubeadm init --pod-network-cidr=192.168.0.0/16
  • 쿠버네티스 초기화 완료후 아래 메세지 복사
kubeadm join xx.xxx.xx.xx:6443 --token cd2pbs.vsmevt7jz0aa3iy5 \
--discovery-token-ca-cert-hash sha256:30efc2ca0e9603fac33bfff7e97229af261167657fdeff2ed5954cbeb8e620d1
  • 환경변수 설정
$ export KUBECONFIG=/etc/kubernetes/admin.conf
  • calico CNI 설치
$ kubectl apply -f [https://docs.projectcalico.org/v3.8/manifests/calico.yaml](https://docs.projectcalico.org/v3.8/manifests/calico.yaml)
  • calico CNI 설치 확인
$ kubectl get po --all-namespaces
NAMESPACE     NAME                                      READY   STATUS    RESTARTS   AGE
kube-system   calico-kube-controllers-bcc6f659f-7rgkm   1/1     Running   0          15h
kube-system   calico-node-lx6lr                         1/1     Running   0          15h
kube-system   calico-node-n9zkp                         1/1     Running   0          15h
kube-system   calico-node-rdmsv                         1/1     Running   0          15h
kube-system   coredns-74ff55c5b-gtdpq                   1/1     Running   0          15h
kube-system   coredns-74ff55c5b-hv5gt                   1/1     Running   0          15h
kube-system   etcd-k8s-master                           1/1     Running   0          15h
kube-system   kube-apiserver-k8s-master                 1/1     Running   0          15h
kube-system   kube-controller-manager-k8s-master        1/1     Running   0          15h
kube-system   kube-proxy-l4cft                          1/1     Running   0          15h
kube-system   kube-proxy-lcwbb                          1/1     Running   0          15h
kube-system   kube-proxy-qm4kw                          1/1     Running   0          15h
kube-system   kube-scheduler-k8s-master                 1/1     Running   0          15h

3. Work Node

  • 쿠버네티스 초기화 완료후 메시지 실행

k8s-work1, k8s-work2 인스턴스에 접속해서 각각 실행한다.

kubeadm join xx.xxx.xx.xx:6443 --token cd2pbs.vsmevt7jz0aa3iy5 \
--discovery-token-ca-cert-hash sha256:30efc2ca0e9603fac33bfff7e97229af261167657fdeff2ed5954cbeb8e620d1

4. Master Node 확인

$ kubectl get no
NAME         STATUS   ROLES                  AGE   VERSION
k8s-master   Ready    control-plane,master   15h   v1.20.1
k8s-node1    Ready    <none>                 15h   v1.20.1
k8s-node2    Ready    <none>                 15h   v1.20.1

참고

https://gruuuuu.github.io/cloud/k8s-install/#