최근 Kubernetes 클러스터 관리에 있어서 Rancher의 인기가 높아지고 있습니다.
이 글에서는 RKE2를 사용하여 Rancher를 설치하고 구성하는 방법을 상세히 설명하고자 합니다.
이 가이드는 Kubernetes 초보자도 쉽게 따라할 수 있도록 구성되어 있습니다.
0. 설치 환경
OS: Ubuntu 20.04.6 LTS
1. RKE2 Install
1) 사전 작업
Kubernetes의 효율적인 활용과 관리를 목표로 하기 위해 swap 메모리를 off 합니다.
swapoff -a
vim /etc/fstab
---
# <file system> <mount point> <type> <options> <dump> <pass>
#/swap.img none swap sw 0 0 # 주석 처리
---
리눅스 시스템 패키지 업데이트 및 업그레이드
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
방화벽 및 네트워크 규칙 초기화
systemctl stop ufw && ufw disable && iptables -F
2) rke2-server 서비스 Install(Master 1)
먼저 RKE2의 공식 Github 저장소에서 RKE2 바이너리를 다운로드 합니다.
# Latest 버전 설치
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="server" sh -
# 특정 버전 설치
curl -sfL https://get.rke2.io | INSTALL_RKE2_VERSION=v1.24.16+rke2r1 INSTALL_RKE2_TYPE="server" sh -
2024-01-27 기준
이 가이드에서는 RKE2 'v1.26.12+rke2r1' 버전을 사용합니다.
rke2-server 서비스를 활성화 합니다.
systemctl enable rke2-server.service
rke2 config를 설정합니다.
mkdir -p /etc/rancher/rke2
vim /etc/rancher/rke2/config.yaml
---
tls-san:
- 192.168.31.171
- 192.168.31.172
- 192.168.31.173
- 192.168.31.174
- 192.168.31.175
- 192.168.31.176
- 192.168.31.177
- 192.168.31.178
---
tls-san은 RKE2 클러스터의 TLS(Transport Layer Security) 설정을 정의합니다.
목록에 포함된 IP 주소들은 클러스터에 접근할 때 사용될 수 있는 호스트 이름이나 IP 주소를 나타냅니다.
클러스터에 안전하게 접근하기 위해 필요한 설정입니다.
rke2-server 서비스를 시작합니다.
systemctl start rke2-server.service
rke2-server 서비스 상태를 확인합니다.
systemctl status rke2-server.service
Kubeconfig 설정을 합니다.
mkdir ~/.kube/
cp /etc/rancher/rke2/rke2.yaml ~/.kube/config
export PATH=$PATH:/var/lib/rancher/rke2/bin/
echo 'export PATH=/usr/local/bin:/var/lib/rancher/rke2/bin:$PATH' >> ~/.bashrc
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
echo "alias k=kubectl" >> ~/.bashrc
echo "complete -F __start_kubectl k" >> ~/.bashrc
source ~/.bashrc
crictl 설정을 합니다.
echo 'export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml' >> ~/.bashrc
export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml
/var/lib/rancher/rke2/bin/crictl ps -a
3) rke2-server 서비스 Install(Master 2/3)
먼저 RKE2의 공식 Github 저장소에서 RKE2 바이너리를 다운로드 합니다.
# Latest 버전 설치
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="server" sh -
# 특정 버전 설치
curl -sfL https://get.rke2.io | INSTALL_RKE2_VERSION=v1.24.16+rke2r1 INSTALL_RKE2_TYPE="server" sh -
2024-01-27 기준
이 가이드에서는 RKE2 'v1.26.12+rke2r1' 버전을 사용합니다.
rke2-server 서비스를 활성화 합니다.
systemctl enable rke2-server.service
기존에 설치한 Master1 node로 가서 Node token 값을 확인합니다.
cat /var/lib/rancher/rke2/server/node-token
---
K105db9dd6874dfd708f50693275ce8481c........
---
rke2 config를 설정합니다.
mkdir -p /etc/rancher/rke2
vim /etc/rancher/rke2/config.yaml
---
server: https://192.168.31.171:9345
token: K105db9dd6874dfd708f50693275ce8481c........
tls-san:
- 192.168.31.171
- 192.168.31.172
- 192.168.31.173
- 192.168.31.174
- 192.168.31.175
- 192.168.31.176
- 192.168.31.177
- 192.168.31.178
---
server는 Master 1의 노드 IP와 rke2 server 통신을 위한 9345 port를 설정합니다.
token은 Master 1의 node-token 값을 입력해 줍니다.
tls-san은
RKE2 클러스터의 TLS(Transport Layer Security) 설정을 정의합니다.
목록에 포함된 IP 주소들은 클러스터에 접근할 때 사용될 수 있는 호스트 이름이나 IP 주소를 나타냅니다.
클러스터에 안전하게 접근하기 위해 필요한 설정입니다.
rke2-server 서비스를 시작합니다.
systemctl start rke2-server.service
rke2-server 서비스 상태를 확인합니다.
systemctl status rke2-server.service
Kubeconfig 설정을 합니다.
mkdir ~/.kube/
cp /etc/rancher/rke2/rke2.yaml ~/.kube/config
export PATH=$PATH:/var/lib/rancher/rke2/bin/
echo 'export PATH=/usr/local/bin:/var/lib/rancher/rke2/bin:$PATH' >> ~/.bashrc
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
echo "alias k=kubectl" >> ~/.bashrc
echo "complete -F __start_kubectl k" >> ~/.bashrc
source ~/.bashrc
crictl 설정을 합니다.
echo 'export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml' >> ~/.bashrc
export CRI_CONFIG_FILE=/var/lib/rancher/rke2/agent/etc/crictl.yaml
/var/lib/rancher/rke2/bin/crictl ps -a
4) rke2-agent 서비스 Install(Worker)
먼저 RKE2의 공식 Github 저장소에서 RKE2 바이너리를 다운로드 합니다.
# Latest 버전 설치
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE="agent" sh -
# 특정 버전 설치
curl -sfL https://get.rke2.io | INSTALL_RKE2_VERSION=v1.24.16+rke2r1 INSTALL_RKE2_TYPE="agent" sh -
2024-01-27 기준
이 가이드에서는 RKE2 'v1.26.12+rke2r1' 버전을 사용합니다.
rke2-agent 서비스를 활성화 합니다.
systemctl enable rke2-agent.service
기존에 설치한 Master1 node로 가서 Node token 값을 확인합니다.
cat /var/lib/rancher/rke2/server/node-token
---
K105db9dd6874dfd708f50693275ce8481c........
---
rke2-agent 서비스를 시작합니다.
systemctl start rke2-agent.service
rke2-agent 서비스 상태를 확인합니다.
systemctl status rke2-agent.service
2. Rancher Install
1) cert-manager Install
GitHub에서 cert-manager의 최신 릴리스 버전을 다운로드하고 설치합니다.
cert-manager는 Kubernetes에서 TLS 인증서를 자동으로 발급하고 관리하는 도구입니다.
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.3/cert-manager.yaml
kubectl -n cert-manager rollout status deploy/cert-manager
---
Waiting for deployment "cert-manager" rollout to finish: 0 of 1 updated replicas are available...
deployment "cert-manager" successfully rolled out
---
kubectl -n cert-manager rollout status deploy/cert-manager-webhook
---
deployment "cert-manager-webhook" successfully rolled out
---
kubectl get pods --namespace cert-manager
---
NAME READY STATUS RESTARTS AGE
cert-manager-77c645c9cd-kws46 1/1 Running 0 47s
cert-manager-cainjector-6678d4cbcd-v9frr 1/1 Running 0 48s
cert-manager-webhook-996c79df8-xmjfd 1/1 Running 0 47s
---
cert-manager를 성공적으로 설치하고, 그 상태를 확인할 수 있습니다.
cert-manager는 Kubernetes 클러스터에서 SSL/TLS 인증서를 관리하는 데 중요한 도구로,
보안 연결을 자동화하는 데 도움을 줍니다
2) Helm Install
Kubernetes의 패키지 관리자인 Helm 3의 설치를 합니다.
Helm 3를 자신의 시스템에 쉽게 설치할 수 있으며,
Helm은 Kubernetes 클러스터에서 애플리케이션의 배포 및 관리를 단순화하는 데 유용한 도구입니다.
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
3) Rancher Install
클러스터에서 Rancher를 설치하는 과정입니다.
# cattle-system 네임스페이스 생성
kubectl create namespace cattle-system
# Rancher의 Helm 차트 저장소 추가 및 업데이트
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
---
"rancher-stable" has been added to your repositories
---
helm repo update
---
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "rancher-stable" chart repository
Update Complete. ⎈Happy Helming!⎈
---
helm search repo rancher-stable
---
NAME CHART VERSION APP VERSION DESCRIPTION
rancher-stable/rancher 2.7.9 v2.7.9 Install Rancher Server to manage Kubernetes clu...
---
# Rancher Install
helm install rancher rancher-stable/rancher \
--namespace cattle-system \
--version 2.7.9 \
--set hostname=rancher.com \
--set replicas=1
---
NAME: rancher
LAST DEPLOYED: Sat Jan 27 07:08:22 2024
NAMESPACE: cattle-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Rancher Server has been installed.
NOTE: Rancher may take several minutes to fully initialize. Please standby while Certificates are being issued, Containers are started and the Ingress rule comes up.
Check out our docs at https://rancher.com/docs/
If you provided your own bootstrap password during installation, browse to https://rancher.com to get started.
If this is the first time you installed Rancher, get started by running this command and clicking the URL it generates:
```
echo https://rancher.com/dashboard/?setup=$(kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}')
```
To get just the bootstrap password on its own, run:
```
kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{ "\n" }}'
```
Happy Containering!
---
Rancher를 설치하는 다양한 옵션 값들이 있습니다.
--namespace: Rancher를 설치할 네임스페이스 지정
--version: Rancher 버전 지정
--set hostname: Rancher 호스트 네임 설정
--set replicas: Rancher replica 설정
이 외에도 다양한 옵션 값들은 공식 문서를 참고 부탁드립니다.
(선택) local에서 /etc/hosts에 Rancher Server의 IP와 도메인을 입력해줍니다.
vim /etc/hosts
---
192.168.31.171 rancher.com # 추가
---
(선택) Rancher Password 설정
- default(12) 값을 수정하여 Password 길이를 조정할 수 있습니다.
kubectl edit settings.management.cattle.io password-min-length
---
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: management.cattle.io/v3
customized: false
default: "12"
kind: Setting
metadata:
creationTimestamp: "2024-01-27T07:09:46Z"
generation: 1
name: password-min-length
resourceVersion: "16014"
uid: a84b7efd-dfe3-4f7b-9639-ef76731c6eaf
source: ""
value: ""
---
4) Rancher 접속
http://<Rancher hostname>
Rancher를 처음 방문했을 때 나타나는 부트스트랩(초기 설정) 비밀번호에 관한 안내입니다.
Rancher 설치 후 최초 로그인 시 설정한 비밀번호가 있다면 그것을 사용하고,
그렇지 않으면 Rancher가 자동으로 생성한 비밀번호를 사용해야 합니다. 비밀번호를 찾는 방법은 다음과 같습니다.
Docker 설치의 경우: `docker ps` 명령어로 컨테이너 ID를 찾은 후,
docker logs [container-id] 2>&1 | grep "Bootstrap Password:" 명령어를 실행하여 비밀번호를 확인합니다.
Helm 설치의 경우: 이 경우에는 특정 명령어를 실행하여 부트스트랩 비밀번호를 확인할 수 있습니다.
이렇게 Rancher 관리자 웹 인터페이스에 최초 로그인하기 위한 부트스트랩 비밀번호를 찾을 수 있습니다.
이 가이드에서는 Helm 설치를 하였기 때문에 아래 방법으로 부트스트랩 비밀번호를 확인합니다.
kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{ "\n" }}'
---
shs78qhz4xwx94gcwglfg2bff....
---
확인한 비밀번호를 입력 후 Log in Local User를 선택합니다.
관리자 비밀번호를 설정합니다.
임의의 비밀번호를 설정할 수 있지만,
Set a specipic password to use를 통해 특정 비밀번호를 입력하는걸 권장합니다.
약관 동의 체크박스를 클릭한 후 Continue
설치완료
3. 마무리
RKE2를 활용한 Rancher 설치에 관한 이 블로그 글을 마무리하며,
여러분이 Rancher를 통해 Kubernetes 클러스터를 보다 효율적으로 관리할 수 있기를 바랍니다.
이 글에서 제공된 단계별 지침을 통해, 여러분은 강력하고 확장 가능한 클러스터 환경을 구축할 수 있을 것입니다.
또한, Rancher의 다양한 기능을 활용하여 클러스터 관리를 더욱 단순화하고, 보안을 강화할 수 있습니다.
이 글이 여러분의 Kubernetes 여정에 도움이 되었기를 희망하며,
추가적인 정보나 도움이 필요하다면 언제든지 문의하세요. Kubernetes의 세계에서 더욱 성장하고 발전하기를 기대합니다.
4. 기타
1) k9s Install
K9s는 Kubernetes 클러스터를 관리하기 위한 터미널 기반의 사용자 인터페이스(UI) 도구입니다.
이는 Kubernetes의 리소스와 클러스터를 관리하고 모니터링하는 데 사용되며,
커맨드 라인 인터페이스(CLI)보다 더 직관적인 방식으로 Kubernetes 클러스터와 상호작용할 수 있게 해줍니다.
K9s는 클러스터 상태를 실시간으로 모니터링하고, 다양한 리소스(팟, 노드, 배포 등)를 관리하는 기능을 제공합니다.
그래픽 사용자 인터페이스(GUI) 대신 터미널 기반 인터페이스를 제공함으로써,
개발자나 시스템 관리자들이 빠르고 효율적으로 작업할 수 있도록 도와줍니다.
K9s는 YAML 파일 편집, 로그 조회, 리소스 상태 확인 등 다양한 작업을 간편하게 수행할 수 있도록 지원합니다.
wget https://github.com/derailed/k9s/releases/download/v0.31.7/k9s_Linux_amd64.tar.gz
tar zxvf k9s_Linux_amd64.tar.gz
chmod a+x k9s
mv k9s /usr/local/bin/
k9s