Installation for test Env.
실험 환경
K8s 구성을 위한 실험 환경은 로컬 VM(on VitualBox) 환경이며,
Cluster NAT와 로컬 호스트와의 통신을 위해, 아래와 같이 두 개의 NIC 인터페이스를 가진다.
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:c7:c8:58 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.5/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s3
valid_lft 760sec preferred_lft 760sec
inet6 fe80::4bb9:8c1a:a15d:1a2f/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:a5:f7:92 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.10/24 brd 192.168.56.255 scope global noprefixroute enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::b6bf:cb94:6d63:3039/64 scope link noprefixroute
valid_lft forever preferred_lft forever
Install Container Runtime
설치 가이드
위 linked page의 지침 中, Docker를 기본으로 설치.
Docker container는 CGroup 커널 기능을 사용하여, 프로세스들의 자원의 사용(CPU, 메모리, 디스크 입출력, 네트워크 등)을 제한하고 격리시킨다.
그러므로, 위 가이드의 Cgroup 드라이버에 관한 내용을 잘 이해하여 적용하도록 해야 한다.
즉, native.cgroupdriver=systemd 설정 부분.
Installing K8s with kubeadm
K8s의 환경을 구성하는 방법에는 다양한 방법이 있으며,
여기에서는 가장 일반적인 kubedam이라는 tool을 사용하여 구성한다.
Requirements & Prechecking
2 GB or more of RAM per machine
2 CPUs or more
Unique hostname, MAC address, and product_uuid for every node.
You can find the following instructions.
Host name:
hostname
MAC address:
ip link
orip a
orifconfig -a
Product uuid:
sudo cat /sys/class/dmi/id/product_uuid
위 값들은 모든 노드들에 걸쳐 유일해야 하며, 그렇지 않으면 설치 과정이 실패할 수 있다.
특히, VM Clone으로 생성한 노드들에 대해 주의(주로 MAC address를 간과하게 됨)가 필요하다.
Full network connectivity between all machines in the cluster (public or private network is fine)
Certain ports are open on your machines.
See here for more details.
Swap disabled.
일시적:
swapoff -a
영구적: /etc/fstab 파일의 swap mount 부분 제거.
Letting iptables see bridged traffic
아래와 같이 확인
$ sudo sysctl -a|egrep "^net\.bridge\.bridge-nf-call-iptables|^net\.bridge\.bridge-nf-call-ip6tables" net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1
만일 결과와 같지 않다면, 아래와 같이 설정 파일을 만들고, sysctl 명령을 통해 반영한다.
$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 EOF $ sudo sysctl --system
Check and open required ports
기본으로 요구되는 port들은 다음과 같다.
Control-plane node(s)
Protocol | Direction | Port Range | Purpose | Used By |
---|---|---|---|---|
TCP | Inbound | 6443* | Kubernetes API server | All |
TCP | Inbound | 2379-2380 | etcd server client API | kube-apiserver, etcd |
TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
TCP | Inbound | 10251 | kube-scheduler | Self |
TCP | Inbound | 10252 | kube-controller-manager | Self |
Worker node(s)
Protocol | Direction | Port Range | Purpose | Used By |
---|---|---|---|---|
TCP | Inbound | 10250 | Kubelet API | Self, Control plane |
TCP | Inbound | 30000-32767 | NodePort Services† | All |
Open ports via Firewalld
위 표에서 나열한 port들을 하나씩 오픈해도 되지만, etcd와 같이 내부 클러스터 통신을 하는 또 다른 pod들을 생성할 수도 있다.
그때마다 따로 지정된 port를 오픈해야 하는 번거로움 때문에 여기서는 Source IP 대역으로 오픈하여 신뢰되는 네트워크 간(Master nodes ↔︎ Worker nodes) 통신은 허용하도록 하였다.
참고로 개별 포트를 오픈하는 방법도 아래 펼침 목록에 넣어두었다.
단, 어떤 방식으로 하든 간에, masquerade
설정은 반드시 적용하여야 한다.
설정하지 않을 시, 서로 다른 node의 pod간 routing이 되지 않는다.
On every k8s nodes
아래에서 192.168.56.0/24
는 호스트와 통신을 위한 대역이다.(위 실험 환경 섹션을 참조 한다.)
나중을 위해 미리 open 해둔다.
$ vim /etc/firewalld/zones/public.xml
<?xml version="1.0" encoding="utf-8"?>
<zone>
<short>Public</short>
<description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
<service name="ssh"/>
<service name="http"/>
<service name="https"/>
<service name="dhcpv6-client"/>
<masquerade/>
<rule family="ipv4">
<source address="10.0.2.0/24"/>
<accept/>
</rule>
<rule family="ipv4">
<source address="10.244.0.0/16"/>
<accept/>
</rule>
<rule family="ipv4">
<source address="192.168.56.0/24"/>
<accept/>
</rule>
</zone>
$ firewall-cmd --reload
Installing kubeadm, kubelet and kubectl
You will install these packages on all of your machines:
kubeadm
: the command to bootstrap the cluster.kubelet
: the component that runs on all of the machines in your cluster and does things like starting pods and containers.kubectl
: the command line util to talk to your cluster.
kubeadm은 모든 마스터 노드의 구성요소(etcd, api server, controller manager, scheduler)를 kubelet을 통해 Pod로 실행하기 때문에 worker node에도 kubelet이 필요하다.
직접 마스터 노드에 구성 요소들을 Docker 데몬(systemd)으로 실행시킬 수도 있다.(번거로움)
Installation instructions on CentOS, RHEL or Fedora
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
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
exclude=kubelet kubeadm kubectl
EOF
# Set SELinux in permissive mode (effectively disabling it)
sudo setenforce 0
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
sudo systemctl enable --now kubelet
위 SELinux 세팅은, 컨테이너가 호스트 파일시스템에 엑세스 하는 것을 허용한다.(예를 들어, pod networks 같은…)
적어도 kubelet에서 보다 향상된 SELinux 지원이 이루어 질 때까지 유지하는 것이 좋다.
Start kubelet
Worker node에서는 kubelet 서비스를 아래처럼 실행하지 않아도 된다.(하더라도 실패할 것이다.)
다음 장에서 살펴볼 kubeadm join
을 하면 자동 실행된다.
sudo systemctl start kubelet
명령으로 실행하고 나서 , journalctl -n1000 -f|grep -i kubelet
를 통해 로그를 보면 /var/lib/kubelet/config.yaml
이 없다고 에러가 난다.
주기(10초)적으로 systemd에 의해 실행되며, 또한 설정 파일에 변경 사항이 발견되면 systemctl daemon-reload && systemctl restart kubelet
이 실행된다.
추후, kuberadm init
으로 자동 생성되면, /var/lib/kubelet/config.yaml
이 생성되며, 정상적으로 데몬이 실행되어 있음을 확인할 수 있다.
kuberadm
을 이용한 cluster 생성 방법은 다음 장에서 다룬다.