CentOS에 Kubernetes 기본 설치하기

이 포스트는 Korea Azure User Group에서 진행하는 Docker/Container 스터디 그룹에 참여하며 작성했습니다.

설치 환경

  • Windows 10 Pro 1809
  • Hyper-V

VM 환경(3대 필요)

  • CentOS 7.6.1810 (Kernel 4.20.2-1.el7)
  • Docker(with YUM)

VM 정보

  • 10.10.0.10 docker-master
  • 10.10.0.11 docker-node01
  • 10.10.0.12 docker-node02

VM 3대 공통 작업

  1. hosts 파일 설정
[root@localhost ~]# vi /etc/hosts
127.0.0.0 docker-master

10.10.0.10 docker-master
10.10.0.11 docker-node01
10.10.0.12 docker-node02
  1. SELinux Off
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  1. br_netfilter 활설화
[root@localhost ~]# modprobe br_netfilter
[root@localhost ~]# echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables

리부팅시 bridge-nf-call-iptables 설정이 되도록 sysctl.conf 설정

[root@localhost ~]# vi /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1

[root@localhost ~]# sysctl -p
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
  1. SWAP 비활성화
[root@localhost ~]# swapoff -a

만약, 별도의 파티션으로 설정되어있을 경우 부팅시 로드되지 않도록 설정

[root@localhost ~]# vi /etc/fstab
#/dev/mapper/centos-swap swap                    swap    defaults        0 0
  1. Docker 설치
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io
  1. Docker driver 변경
[root@localhost ~]# mkdir /etc/docker
[root@localhost ~]# 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
[root@localhost ~]# mkdir -p /etc/systemd/system/docker.service.d
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl restart docker
  1. Kubernetes 저장소 설치
[root@localhost ~]# cat > /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=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
  1. Kubernetes 설치 및 리부팅
[root@localhost ~]# yum install -y kubelet kubeadm kubectl
[root@localhost ~]# init 6
  1. Docker 실행 및 서비스 등록
[root@localhost ~]# systemctl start docker && systemctl enable docker

Kubernetes 구성진행

  • Kubernetes Master 구성
[root@docker-master ~]# kubeadm init --apiserver-advertise-address=10.10.0.10 --pod-network-cidr=10.244.0.0/16
[init] Using Kubernetes version: v1.13.4
[preflight] Running pre-flight checks
        [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 18.09.3. Latest validated version: 18.06
[preflight] Pulling images required for setting up a Kubernetes cluster
[preflight] This might take a minute or two, depending on the speed of your internet connection
[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Activating the kubelet service
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
.....
[bootstraptoken] creating the "cluster-info" ConfigMap in the "kube-public" namespace
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes master has initialized successfully!

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 10.10.0.10:6443 --token js8tf4.v982thq1qg07108g --discovery-token-ca-cert-hash sha256:3eea875dec8f2aa1650afe0bbb2165b7abcb98480bcd9e51c12355755ddf55b5

[root@docker-master ~]# mkdir -p $HOME/.kube
[root@docker-master ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@docker-master ~]# chown $(id -u):$(id -g) $HOME/.kube/config 

Kubernetes 나머지 노드에서 실행

[root@docker-node01 ~]# kubeadm join 10.10.0.10:6443 --token js8tf4.v982thq1qg07108g --discovery-token-ca-cert-hash sha256:3eea875dec8f2aa1650afe0bbb2165b7abcb98480bcd9e51c12355755ddf55b5

[root@docker-node02 ~]# kubeadm join 10.10.0.10:6443 --token js8tf4.v982thq1qg07108g --discovery-token-ca-cert-hash sha256:3eea875dec8f2aa1650afe0bbb2165b7abcb98480bcd9e51c12355755ddf55b5

Kuvernetes network 배포(flannel)

[root@docker-master ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

Kubernetes Master에서 노드 연결 확인

[root@docker-master ~]# kubectl get node
NAME            STATUS   ROLES    AGE   VERSION
docker-master   Ready    master   40h   v1.13.4
docker-node01   Ready    <none>   40h   v1.13.4
docker-node02   Ready    <none>   40h   v1.13.4

참고링크