Kubernetes #4-2. Kubernetes 클러스터 구축 – 단일 마스터노드 클러스터 생성 (offline, 폐쇄망)

[Kubernetes #1. 사전작업 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – 컨테이너 런타임 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – docker 설정 (offline, 폐쇄망)]
[Kubernetes #3. Kubernetes 바이너리 설치 (offline, 폐쇄망)]
[Kubernetes #4. Kubernetes 클러스터 구축 – image pull (offline, 폐쇄망)]
[Kubernetes #4-2. Kubernetes 클러스터 구축 – 단일 마스터노드 생성 (offline, 폐쇄망)]
[Kubernetes #4-3. Kubernetes 클러스터 구축 – worker node join (offline, 폐쇄망)]

kubeadm init

sudo kubeadm init –apiserver-advertise-address $MASTER_NODE_IP_ADDRESS –pod-network-cidr=10.244.0.0/16
명령을 수행하면 설치가 시작된다.
–apiserver-advertise-address : 마스터노드 IP
–pod-network-cidr : pod간 통신을 위한 내부 네트워크 CIDR 1사이더(Classless Inter-Domain Routing, CIDR)는 클래스 없는 도메인 간 라우팅 기법으로 1993년 도입되기 시작한, 최신의 IP 주소 할당 방법이다. 사이더는 기존의 IP 주소 할당 방식이었던 네트워크 클래스를 대체하였다. 사이더는 IP 주소의 영역을 여러 네트워크 영역으로 나눌 때 기존방식에 비해 유연성을 더해준다. 특히 다음과 같은 장점이 있다.
급격히 부족해지는 IPv4 주소를 보다 효율적으로 사용하게 해준다.
접두어를 이용한 주소 지정 방식을 가지는 계층적 구조를 사용함으로써 인터넷 광역 라우팅의 부담을 줄여준다.

sudo    kubeadm   init   --apiserver-advertise-address $MASTER_NODE_IP_ADDRESS --pod-network-cidr=10.244.0.0/16

...전략...
[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key
[addons] Applied essential addon: CoreDNS
[addons] Applied essential addon: kube-proxy

Your Kubernetes control-plane 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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

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/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.192.168:6443 --token abcdefg.8rpr4mfmetbabcde --discovery-token-ca-cert-hash sha256:3a12345caaef12334567890cd3953d1234c3904ab70a8b949f32d6df12345
  • /etc/kubernetes/admin.conf 에는 마스터노드의 kube-proxy 관련 정보가 들어있다. mkdir 부터 시작하는 명령을 수행해줘야 kubectl 명령을 사용할 수 있다.
  • 마지막 kubeadm join 명령은 worker 노드를 추가하기 위한 명령이다. worker 노드가 될 서버에kubernetes 관련 패키지(kueadm,kubectl,kubelet 및 image 등)를 설치한 뒤 수행해주면 worker 노드로 클러스터의 멤버가 된다. token 관련 값은 24시간의 유효시간이 있으므로 나중에 클러스터 멤버로 join 하려면 새로 새로 발행해야 한다.

확인

init 스크립트가 완료되고 kubernetes config 관련 설정을 마쳤다면 kubectl 명령을 사용할 수 있다. 다음 명령을 통해 상태를 확인한다.

kubectl get nodes
NAME      STATUS     ROLES                  AGE   VERSION
centos7   NotReady   control-plane,master   20s   v1.23.5

현재 노드의 status 가 NotReady로 나오지만 정상적으로 설정 된 것이다.

Kubernetes #3. Kubernetes 바이너리 설치 (offline, 폐쇄망)

[Kubernetes #1. 사전작업 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – 컨테이너 런타임 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – docker 설정 (offline, 폐쇄망)]
[Kubernetes #3. Kubernetes 바이너리 설치 (offline, 폐쇄망)]
[Kubernetes #4. Kubernetes 클러스터 구축 – image pull (offline, 폐쇄망)]
[Kubernetes #4-2. Kubernetes 클러스터 구축 – 단일 마스터노드 생성 (offline, 폐쇄망)]
[Kubernetes #4-3. Kubernetes 클러스터 구축 – worker node join (offline, 폐쇄망)]

Yum repository를 추가해서 설치하는 방법, 바이너리를 직접 다운로드 한 다음 스크립트를 생성하는 방법, 두 가지가 있다

이 포스트의 작업은 쿠버네티스 클러스터에 포함하는 모든 노드에서 수행해야 한다.

      

패키지 매니저를 이용한 설치

CentOS yum repository 추가

sudo 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

Ubunt

sudo apt-get install -y apt-transport-https ca-certificates curl
# 구글 클라우드의 공개 signing 키 다운로드
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
# Kubernetes 리포지터리 추가
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

      

패키지 설치

CentOS

sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

Ubuntu

sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

      

서비스 등록 및 활성화

CentOS, Ubuntu 동일

sudo systemctl enable kubelet.service

sudo systemctl start kubelet.service

      

      

바이너리 다운로드를 통한 설치

CNI 플러그인1yum 등을 이용해서 설치하는 경우 의존성 패키지로 설치된다., kubeadm, kubelet, kubectl 을 설치한다.

아래 설명에서 curl 대신 wget을 이용하거나, 작업중인 PC에서 다운로드 후 업로드 하는 방법으로 대체해도 무방하다.

CNI 플러그인 설치

CNI_VERSION="v0.8.2" 
sudo mkdir -p /opt/cni/bin
curl -L "https://github.com/containernetworking/plugins/releases/download/${CNI_VERSION}/cni-plugins-linux-amd64-${CNI_VERSION}.tgz" | sudo tar -C /opt/cni/bin -xz
#curl -LO 옵션으로 다운로드 후 별도로 압축을 해제해도 된다. 이 경우 압축 해제된 파일을 /opt/cni/bin 디렉토리로 이동 해야 한다.

clictl 설치

DOWNLOAD_DIR=/usr/local/bin
sudo mkdir -p $DOWNLOAD_DIR

kubeadm, kubelet, kubectl 바이너리 설치

RELEASE="$(curl -sSL https://dl.k8s.io/release/stable.txt)" 
cd $DOWNLOAD_DIR
sudo curl -L --remote-name-all https://storage.googleapis.com/kubernetes-release/release/${RELEASE}/bin/linux/amd64/{kubeadm,kubelet,kubectl}
sudo chmod +x {kubeadm,kubelet,kubectl}

서비스 스크립트 다운로드

RELEASE_VERSION="v0.4.0" 
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubelet/lib/systemd/system/kubelet.service" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service
sudo mkdir -p /etc/systemd/system/kubelet.service.d
curl -sSL "https://raw.githubusercontent.com/kubernetes/release/${RELEASE_VERSION}/cmd/kubepkg/templates/latest/deb/kubeadm/10-kubeadm.conf" | sed "s:/usr/bin:${DOWNLOAD_DIR}:g" | sudo tee /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

 

서비스 스크립트 생성 (위 스크립트 다운로드 방법 대체)

sudo vi /etc/systemd/system/kubelet.service
# 아래 내용을 붙여넣기 한다.
[Unit]
Description=kubelet: The Kubernetes Node Agent
Documentation=https://kubernetes.io/docs/home/
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/bin/kubelet
Restart=always
StartLimitInterval=0
RestartSec=10

[Install]
WantedBy=multi-user.target
sudo vi /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# 아래 내용을 붙여넣기 한다.
# Note: This dropin only works with kubeadm and kubelet v1.11+
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_CONFIG_ARGS=--config=/var/lib/kubelet/config.yaml"
# This is a file that "kubeadm init" and "kubeadm join" generates at runtime, populating the KUBELET_KUBEADM_ARGS variable dynamically
EnvironmentFile=-/var/lib/kubelet/kubeadm-flags.env
# This is a file that the user can use for overrides of the kubelet args as a last resort. Preferably, the user should use
# the .NodeRegistration.KubeletExtraArgs object in the configuration files instead. KUBELET_EXTRA_ARGS should be sourced from this file.
EnvironmentFile=-/etc/default/kubelet
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_CONFIG_ARGS $KUBELET_KUBEADM_ARGS $KUBELET_EXTRA_ARGS

 

서비스 등록 및 시작

systemctl enable kubelet.service
systemctl start kubelet.service

 

 

 

 

Kubernetes #2-2. 사전작업 – docker 설정 (offline, 폐쇄망)

[Kubernetes #1. 사전작업 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – 컨테이너 런타임 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – docker 설정 (offline, 폐쇄망)]
[Kubernetes #3. Kubernetes 바이너리 설치 (offline, 폐쇄망)]
[Kubernetes #4. Kubernetes 클러스터 구축 – image pull (offline, 폐쇄망)]
[Kubernetes #4-2. Kubernetes 클러스터 구축 – 단일 마스터노드 생성 (offline, 폐쇄망)]
[Kubernetes #4-3. Kubernetes 클러스터 구축 – worker node join (offline, 폐쇄망)]

망분리 환경에서 proxy등을 통한 외부 연결이 가능하거나, 망 내부적으로 proxy를 통해 통신하는 경우 proxy 설정이 필요하다.
linux OS 레벨에서는 .bash_profile 등에 proxy 변수를 등록하는 것으로 처리가 가능하지만 docker 런타임은 별도로 proxy 정보를 정의해 줘야 한다

이 포스트의 작업은 쿠버네티스 클러스터에 포함하는 모든 노드에서 수행해야 한다.

     

Docker Proxy 설정

서비스 설정 (docker login 등의 작업 에 사용된다.)

[haedong@haedong:~:]$ sudo /lib/systemd/system/docker.service
전략...
# [service] 섹션에 아래 추가
Environment="HTTP_PROXY=http://120.121.122.123:8080" 
Environment="HTTPS_PROXY=https://120.121.122.123:8080" 
Environment="NO_PROXY=.haedong.net,localhost,127.0.0.1/8,192.168.0.0/16,.local" 
[haedong@haedong:~:]$ sudo systemctl daemon-reload
[haedong@haedong:~:]$ sudo systemctl restart docker.service

컨테이너 설행 시 변수로 전달

[haedong@haedong:~]$ docker run \
-e http_proxy=http://120.121.122.123:8080 \
-e https_proxy https://120.121.122.123:8080 \
-e no_proxy .haedong.net,localhost,127.0.0.1/8,192.168.0.0/16,.local \
CONTAINER_NAME

이미지 빌드 시 포함

ENV PATH /home/haedong/bin:$PATH
ENV LD_LIBRARY_PATH /lib:/lib64:$LD_LIBRARY_PATH
...중략...
# 아래 내용 추가
ENV http_proxy http://120.121.122.123:8080
ENV https_proxy https://120.121.122.123:8080
ENV no_proxy .haedong.net,localhost,127.0.0.1/8,192.168.0.0/16,.local

     

Docker root directory 변경

pull 한 image나 컨테이너 임시 데이터 등이 저장되는 디렉토리이다. 기본 값은 /var/lib/docker 인데, /var directory가 포함된 파티션의 크기가 작거나 하는 경우 disk full 로 인해 문제를 야기할 수 있다.

현재 docker root 확인

docker info | grep "Docker Root Dir" 

 Docker Root Dir: /var/lib/docker

#docker volume inspect my-vol

준비

docker root dirctory로 사용할 디스크를 확정하고 파티션 생성, 마운트 등의 작업을 마친다.
sudo systemctl stop docker.service 명령으로 서비스를 중지하고(시간이 걸릴 수 있다. 프로세스가 완전히 사라졌는지 확인하도록 하자) 이전의 docker 파일들을 대상 디렉토리로 복사한다.

mkdir /data
cp -rp /var/lib/docker /data

     

서비스 수정

sudo vi /usr/lib/systemd/system/docker.service
# Service 섹션에 ExecStart= 로 시작하는 줄을 수정한다.
# ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --data-root=/data
sudo systemctl daemon-reload
sudo systemctl restart docker.service

     

cgroup driver 변경

현재 상태 확인

sudo docker info | grep cgroup
 Cgroup Driver: cgroupfs

서비스 수정

sudo vi /etc/systemd/system/docker.service

# ExecStart 로 시작하는 줄에  --exec-opt native.cgroupdriver=systemd 추가
# ExecStart=/usr/bin/dockerd -g /home/data/ -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -g /home/data/ -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd
sudo systemctl daemon-reload
sudo systemctl restart docker.service

Kubernetes #2-2. 사전작업 – 컨테이너 런타임 (offline, 폐쇄망)

[Kubernetes #1. 사전작업 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – 컨테이너 런타임 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – docker 설정 (offline, 폐쇄망)]
[Kubernetes #3. Kubernetes 바이너리 설치 (offline, 폐쇄망)]
[Kubernetes #4. Kubernetes 클러스터 구축 – image pull (offline, 폐쇄망)]
[Kubernetes #4-2. Kubernetes 클러스터 구축 – 단일 마스터노드 생성 (offline, 폐쇄망)]
[Kubernetes #4-3. Kubernetes 클러스터 구축 – worker node join (offline, 폐쇄망)]

쿠버네티스는 ‘컨테이너를 관리’ 하는 녀석이다. 즉, 쿠버네티스만으로는 아무 것도 할 수 없다는 이야기. 컨테이너 실행을 위해 런타임이 필요하다. Docker, Containerd, CRI-O 등이 있다.
이 포스트에서는 docker를 기준으로 설명한다.

외부에서 repo 파일을 다운로드 받아서 폐쇄망의 클러스터에 복사하거나, –downloadonly 등의 옵션으로 패키지를 다운로드 해서 복사 한다음 설치해야 한다.

이 포스트의 작업은 쿠버네티스 클러스터에 포함하는 모든 노드에서 수행해야 한다.

 

이전 버전의 docker 제거

CentOS (CentOS7 기준)

sudo yum remove docker docker-client docker-client-latest docker-common \
                  docker-latest docker-latest-logrotate docker-logrotate docker-engine

Ubuntu (Ubuntu18 기준)

sudo apt-get remove docker docker-engine docker.io containerd runc

 

설치를 위한 패키지와 repository 등록

CentOS

sudo yum install -y yum-utils
# yum-config-manager를 위한 패키지

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum-utils 패키지 설치를 생략하고 docker-ce.repo 파일을 다운로드 받아서 /etc/yum.repos.d/에 복사해도 된다.

sudo yum clean all
# yum 캐시 정리 캐시 파일이 너무 크거나 문제가 있는 경우 sudo rm -rf /var/cache/yum 명령 수행

sudo yum repolist
# 패키지 목록 업데이트

Ubuntu

sudo apt-get update
# apt 패키지 목록 업데이트

sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
# 패키지 설치 및 rpository 업데이트 등을 위한 패키지 설치

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# gpg key 등록

sudo echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# docker repository 등록

sudo apt-get update

 

Docker 엔진설치

CentOS

sudo yum -y install docker-ce docker-ce-cli containerd.io

Ubuntu

sudo apt-get install docker-ce docker-ce-cli containerd.io

 

서비스 시작 및 활성화

CentOS / Ubuntu 동일

sudo systemctl enable docker.service
# 서비스 활성화 (부팅 시 자동 시작)

sudo systemctl start docker.service
# 서비스 시작

 

특정 버전을 설치하자 하는 경우

# CentOS
yum list docker-ce --showduplicates | sort -r
 sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli- containerd.io

	
#Ubuntu
apt-cache madison docker-ce
 docker-ce | 5:20.10.8~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.7~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.6~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.5~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.4~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.3~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.2~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.1~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
 docker-ce | 5:20.10.0~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages
...후략
출력되는 목록에서 버전 확인 후 설치
sudo apt-get install docker-ce= docker-ce-cli= containerd.io

Kubernetes #1. 사전작업 (offline, 폐쇄망)

[Kubernetes #1. 사전작업 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – 컨테이너 런타임 (offline, 폐쇄망)]
[Kubernetes #2-2. 사전작업 – docker 설정 (offline, 폐쇄망)]
[Kubernetes #3. Kubernetes 바이너리 설치 (offline, 폐쇄망)]
[Kubernetes #4. Kubernetes 클러스터 구축 – image pull (offline, 폐쇄망)]
[Kubernetes #4-2. Kubernetes 클러스터 구축 – 단일 마스터노드 생성 (offline, 폐쇄망)]
[Kubernetes #4-3. Kubernetes 클러스터 구축 – worker node join (offline, 폐쇄망)]

쿠버네티스 공식 홈페이지의 가이드를 따르면 쉽게 설치할 수 있다.
하지만 경우에 따라 외부 연결이 불가능한 폐쇄망 등에 설치해야 하는 경우를 가정하여 설치하는 방법을 설명한다. (물론 이 방법도 쿠버네티스 공식 홈페이지에 잘 설명되어있다.)

기본적으로 쿠버네티스 클러스터는 노드간 통신에 별도의 네트워크를 사용한다.
(별도의 물리적 변경이 아닌 가상 환경) 이를 위해 브릿지 관련 설정을 변경한다.

이 포스트의 작업은 쿠버네티스 클러스터에 포함하는 모든 노드에서 수행해야 한다.

브릿지 네트워크 관련 설정 변경

[haedong@haedongg.net:~]$ sudo cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
[haedong@haedongg.net:~]$ sudo cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
[haedong@haedongg.net:~]$ sudo sysctl --system
[haedong@haedongg.net:~]$ sudo sysctl -p 
net.ipv4.tcp_keepalive_time = 160
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 2
net.ipv4.conf.all.rp_filter = 2
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.tcp_syncookies = 1
vm.min_free_kbytes = 524288
...중략
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-arptables = 1
...생략

SELINUX 해제

[haedong@haedongg.net:~]$ vi /etc/selinux/config
...중략...
# 기본값은 SELINUX=enforced disabled로 수정한다.
SELINUX=disabled 
...생략

 

swap 메모리 해제

swap 여부 확인

[haedong@haedongg.net:~]$ free -g
              total        used        free      shared  buff/cache   available
Mem:             62           3           0           0          57          57
Swap:            99           0          99

swap 해제

[haedong@haedongg.net:~]$ swapoff -a

해제 확인

[haedong@haedongg.net:~]$ free -g
              total        used        free      shared  buff/cache   available
Mem:             62           3           0           0          57          57
Swap:             0           0           0

fstab 수정 ( swap 파티션이 마운트되지 않도록 설정)

[haedong@haedongg.net:~]$ sudo vi /etc/fstab
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=111f15c1-7697-4597-1234-b7f231009876 /boot                   xfs     defaults        0 0
#/dev/mapper/centos-home /home                   xfs     defaults        0 0
# 아래 줄을 주석처리 한다.
#/dev/mapper/centos-swap swap                    swap    defaults        0 0

 

hostname 과 hosts 파일 수정

쿠버네티스는 기본적으로 kubeadm init 시 hostname을 참조한다. 별도의 DNS를 사용하지 않는다면 /etc/hosts 파일에 호스트 명과 IP 정보를 적어준다.

[haedong@haedongg.net:~]$ vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

# 현재 서버의 정보가 없을 경우 다음 줄 추가 
192.168.192.168 haedongg.net

Kubesphere #1. 설치

Kubephere는 플러그앤 플레이 아키텍쳐를 통해 타사 애플리케이션을 해당 에코시스템에 원활하게 통합할 수 있는 kubernetes를 커널로 하는 클라우드 네이티브 애플리케이션 관리를 위한 분산 운영체제 이다.kubesphere 홈페이지 발췌

설치는 Kubesphere 홈페이지를 참고했다.

Kubesphere는 다음 Kubernetes 런타임을 지원한다.

Supported Container RuntimeVersion
Docker19.3.8 +
containerd (experimental, not fully tested)Latest
CRI-O (experimental, not fully tested)Latest
iSula (experimental, not fully tested)Latest

본 예제는 총 4대의 가상머신 (CentOS7, 4core CPU, 8GB RAM, 128GB storage)으로 테스트 하였다.

작업을 시작하기 전에 이 포스트를 참고하여 kubesphere 구성을 할 서버들 간의 SSH key를 맞춰주도록 한다.

의존성 패키지 설치
kubernetes v1.18 이상은 socat과 conntrack 패키지가 필요하고 ebtables와 ipset 패키지는 권장, v1.18 미만은 모두 설치를 권장한다.

haedong@haedong:~/kubesphere:]$ sudo yum install socat conntrack ebtables ipset
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
Package socat-1.7.3.2-2.el7.x86_64 already installed and latest version
...중략...
---> Package libnetfilter_queue.x86_64 0:1.0.2-2.el7_2 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==========================================================================================================================================================================================
 Package                                              Arch                                 Version                                       Repository                                  Size
==========================================================================================================================================================================================
Installing:
 conntrack-tools                                      x86_64                               1.4.4-7.el7                                   ...중략...
local_centos                                23 k
Transaction Summary
==========================================================================================================================================================================================
Install  1 Package (+3 Dependent packages)
Total download size: 245 k
(4/4): libnetfilter_queue-1.0.2-2.el7_2.x86_64.rpm                                                                                                                 ...중략...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                     1.6 MB/s | 245 kB  00:00:00
Running transaction check
...중략...
  Verifying  : libnetfilter_queue-1.0.2-2.el7_2.x86_64                                                                                                                                4/4
Installed:
  conntrack-tools.x86_64 0:1.4.4-7.el7
...중략...
Complete!

Kubesphere는 다음 port들을 사용한다. 본인 소유의 시스템이 아니라면 관리자에 다음 표의 포트 개방을 요청 해야 한다.

ServiceProtocolActionStart PortEnd PortNotes
sshTCPallow22
etcdTCPallow23792380
apiserverTCPallow6443
calicoTCPallow90999100
bgpTCPallow179
nodeportTCPallow3000032767
masterTCPallow1025010258
dnsTCPallow53
dnsUDPallow53
local-registryTCPallow5000For the offline environment
local-aptTCPallow5080For the offline environment
rpcbindTCPallow111Required if NFS is used
ipipIPENCAP / IPIPallowCalico needs to allow the ipip protocol
metrics-serverTCPallow8443

Kubekey 다운로드

haedong@kubesphere-01:~:]$ curl -ksfL https://get-kk.kubesphere.io | VERSION=v1.1.1 sh -
Downloading kubekey v1.1.1 from https://github.com/kubesphere/kubekey/releases/download/v1.1.1/kubekey-v1.1.1-linux-amd64.tar.gz ...
Failed to download Kubekey v1.1.1 !
Please verify the version you are trying to download.

잘 안된다…… github 릴리즈 페이지에서 다운로드 하자.

haedong@kubesphere-01:~:]$ wget --no-check-certificate https://github.com/kubesphere/kubekey/releases/download/v1.1.1/kubekey-v1.1.1-linux-amd64.tar.gz
--2021-08-25 14:53:24--  https://github.com/kubesphere/kubekey/releases/download/v1.1.1/kubekey-v1.1.1-linux-amd64.tar.gz
Connecting to 168.219.61.252:8080... connected.
...중략...
Length: 13341858 (13M) [application/octet-stream]
Saving to: ‘kubekey-v1.1.1-linux-amd64.tar.gz’

100%[================================================================================================================================================>] 13,341,858  3.14MB/s   in 4.4s

2021-08-25 14:53:30 (2.88 MB/s) - ‘kubekey-v1.1.1-linux-amd64.tar.gz’ saved [13341858/13341858]

압축을 해제하고 권한을 변경한다.

haedong@kubesphere-01:~:]$ tar -xvzf kubekey-v1.1.1-linux-amd64.tar.gz
README.md
README_zh-CN.md
kk
haedong@kubesphere-01:~:]$ chmod +x kk
haedong@kubesphere-01:~:]$ ll
합계 26428
-rw-r--r-- 1 haedong haedong    22906  7월 12 16:00 README.md
-rw-r--r-- 1 haedong haedong    22845  7월 12 16:00 README_zh-CN.md
-rwxr-xr-x 1 haedong haedong 13668116  7월 12 16:02 kk
-rw-rw-r-- 1 haedong haedong 13341858  7월 12 16:03 kubekey-v1.1.1-linux-amd64.tar.gz

설치
다운로드한 kk가 지원하는 kubernetes 버전을 확인한다. 1예제는 Kubekey를 이용해 Kubesphere와 Kubernetes를 함께 설치하는 방법을 나열한다. 기존에 설치되어있는 Kubernetes를 이용하는 경우는 여기를 눌러 설치 방법을 확인하면 된다.

haedong@kubesphere-01:~:]$ ./kk version --show-supported-k8s
v1.15.12
v1.16.8
v1.16.10
v1.16.12
v1.16.13
v1.17.0
v1.17.4
v1.17.5
v1.17.6
v1.17.7
v1.17.8
v1.17.9
v1.18.3
v1.18.5
v1.18.6
v1.18.8
v1.19.0
v1.19.8
v1.19.9
v1.20.4
v1.20.6

다음 템플릿대로 실행하면 된다
./kk create cluster [–with-kubernetes version] [–with-kubesphere version]

만약 부족한 패키지가 있다면 다음과 같이 표시될 것이다.

haedong@kubesphere-01:~:]$ sudo ./kk create cluster --with-kubernetes v1.20.4 --with-kubesphere v3.1.1
[sudo] haedong의 암호:
+---------------+------+------+---------+----------+-------+-------+-----------+--------+------------+-------------+------------------+--------------+
| name          | sudo | curl | openssl | ebtables | socat | ipset | conntrack | docker | nfs client | ceph client | glusterfs client | time         |
+---------------+------+------+---------+----------+-------+-------+-----------+--------+------------+-------------+------------------+--------------+
| kubesphere-01 | y    | y    | y       | y        |       | y     |           |        | y          |             |                  | KST 15:17:51 |
+---------------+------+------+---------+----------+-------+-------+-----------+--------+------------+-------------+------------------+--------------+
kubesphere-01: conntrack is required.

필요한 패키지가 모두 설치 되어있다면 다음과 같이 진행 된다.

haedong@kubesphere-01:~:]# sudo./kk create cluster --with-kubernetes v1.20.4 --with-kubesphere v3.1.1
+--------+------+------+---------+----------+-------+-------+-----------+---------+------------+-------------+------------------+---------                               -----+
| name   | sudo | curl | openssl | ebtables | socat | ipset | conntrack | docker  | nfs client | ceph client | glusterfs client | time                                        |
+--------+------+------+---------+----------+-------+-------+-----------+---------+------------+-------------+------------------+---------                               -----+
| kube01 | y    | y    | y       | y        | y     | y     | y         | 20.10.8 | y          |             |                  | KST 09:5                               2:43 |
+--------+------+------+---------+----------+-------+-------+-----------+---------+------------+-------------+------------------+---------                               -----+

This is a simple check of your environment.
Before installation, you should ensure that your machines meet all requirements specified at
https://github.com/kubesphere/kubekey#requirements-and-recommendations

Continue this installation? [yes/no]: yes
INFO[09:52:45 KST] Downloading Installation Files
INFO[09:52:45 KST] Downloading kubeadm ...
INFO[09:52:49 KST] Downloading kubelet ...
INFO[09:53:00 KST] Downloading kubectl ...
INFO[09:53:07 KST] Downloading helm ...
INFO[09:53:11 KST] Downloading kubecni ...
INFO[09:53:18 KST] Configuring operating system ...

...중략...

clusterconfiguration.installer.kubesphere.io/ks-installer created
#####################################################
###              Welcome to KubeSphere!           ###
#####################################################

Console: http://0.0.0.0:30880
Account: admin
Password: P@88w0rd

NOTES:
  1. After you log into the console, please check the
     monitoring status of service components in
     "Cluster Management". If any service is not
     ready, please wait patiently until all components
     are up and running.
  2. Please change the default password after login.

#####################################################
https://kubesphere.io             2021-09-07 10:00:00
#####################################################
INFO[10:00:11 KST] Installation is complete.

Please check the result using the command:

       kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f

You have new mail in /var/spool/mail/root

kubekey를 이용한 설치 시 31개의 Docker image를 가져오게 되는데 운영 환경 제약 등으로 실패할 경우 아래 명령을 이용해 설치 전 이미지를 다운 받으면 된다.

docker pull docker.io/kubesphere/ks-installer:v3.1.1  &&\
docker pull docker.io/kubesphere/ks-controller-manager:v3.1.1  &&\
docker pull docker.io/kubesphere/ks-apiserver:v3.1.1  &&\
docker pull docker.io/kubesphere/ks-console:v3.1.1  &&\
docker pull docker.io/openebs/provisioner-localpv:2.10.1  &&\
docker pull docker.io/kubesphere/notification-manager:v1.0.0  &&\
docker pull docker.io/kubesphere/notification-manager-operator:v1.0.0  &&\
docker pull docker.io/openebs/linux-utils:2.10.0  &&\
docker pull docker.io/kubesphere/kubectl:v1.20.0 &&\
docker pull docker.io/prom/prometheus:v2.26.0 &&\
docker pull docker.io/kubesphere/kube-proxy:v1.20.4 &&\
docker pull docker.io/kubesphere/kube-apiserver:v1.20.4 &&\
docker pull docker.io/kubesphere/kube-controller-manager:v1.20.4 &&\
docker pull docker.io/kubesphere/kube-scheduler:v1.20.4 &&\
docker pull docker.io/csiplugin/snapshot-controller:v3.0.3  &&\
docker pull docker.io/kubesphere/kube-rbac-proxy:v0.8.0  &&\
docker pull docker.io/calico/node:v3.16.3 &&\
docker pull docker.io/calico/pod2daemon-flexvol:v3.16.3 &&\
docker pull docker.io/calico/cni:v3.16.3 &&\
docker pull docker.io/calico/kube-controllers:v3.16.3 &&\
docker pull docker.io/kubesphere/prometheus-config-reloader:v0.42.1 &&\
docker pull docker.io/kubesphere/prometheus-operator:v0.42.1 &&\
docker pull docker.io/kubesphere/etcd:v3.4.13 &&\
docker pull docker.io/prom/alertmanager:v0.21.0 &&\
docker pull docker.io/kubesphere/kube-state-metrics:v1.9.7  &&\
docker pull docker.io/kubesphere/k8s-dns-node-cache:1.15.12 &&\
docker pull docker.io/coredns/coredns:1.6.9   &&\
docker pull docker.io/kubesphere/pause:3.2     &&\
docker pull docker.io/jimmidyson/configmap-reload:v0.3.0  &&\
docker pull docker.io/prom/node-exporter:v0.18.1 &&\
docker pull docker.io/mirrorgooglecontainers/defaultbackend-amd64:1.4    

일반적인 환경에서는

haedong@kubesphere-01:~:]$ curl -ksfL https://get-kk.kubesphere.io | VERSION=v1.1.1 sh -
haedong@kubesphere-01:~:]# sudo./kk create cluster --with-kubernetes v1.20.4 --with-kubesphere v3.1.1

위 두 줄 명령으로 설치가 진행되지만 특수한 환경에서는2 Proxy를 통한 외부 연결 등
Docker runtime 설치 -> Docker service 스크립트에 proxy 정보 추가 -> image pull -> 설치 의 순서로 진행해야 할 수 있다.