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 디렉토리로 이동 해야 한다.
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
본 예제는 총 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들을 사용한다. 본인 소유의 시스템이 아니라면 관리자에 다음 표의 포트 개방을 요청 해야 한다.
Service
Protocol
Action
Start Port
End Port
Notes
ssh
TCP
allow
22
etcd
TCP
allow
2379
2380
apiserver
TCP
allow
6443
calico
TCP
allow
9099
9100
bgp
TCP
allow
179
nodeport
TCP
allow
30000
32767
master
TCP
allow
10250
10258
dns
TCP
allow
53
dns
UDP
allow
53
local-registry
TCP
allow
5000
For the offline environment
local-apt
TCP
allow
5080
For the offline environment
rpcbind
TCP
allow
111
Required if NFS is used
ipip
IPENCAP / IPIP
allow
Calico needs to allow the ipip protocol
metrics-server
TCP
allow
8443
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.
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:~:]$ 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를 가져오게 되는데 운영 환경 제약 등으로 실패할 경우 아래 명령을 이용해 설치 전 이미지를 다운 받으면 된다.
kubeadm, kubectl, kubelet 설치 이 글을 작성하는 시점의 kubelet은 v1.22.1인데 controlplane은 v1.21.0이다. 이 경우 다음 절의 kubadm 초기화 시 버전 차이로 인해 에러가 발생한다. RELEASE를 v1.21.1로 고정하여 다운로드 한다.