multi-cluster-devops

Lab 2. Install Rancher for Managing Multi Clusters

Rancher Config


1. Install Rancher

# 설치할 클러스터의 노드 확인
$ kubectl get nodes

# cert-manager 설치
$ kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.10.0/cert-manager.yaml

# Rancher helm 레파지토리 등록
$ helm repo add rancher-latest https://releases.rancher.com/server-charts/latest 

# Rancher 설치
# 원하는 도메인 명 등록 후 해당 도메인 명으로 접속
$ helm upgrade -i rancher rancher-latest/rancher \
--set hostname=rancher.kw01 --set bootstrapPassword=admin \
--set replicas=1 --set global.cattle.psp.enabled=false \
--create-namespace -n cattle-system

# Rancher 구동 확인
$ kubectl get pods -l app=rancher -A
$ kubectl rollout status deploy rancher -n cattle-system


# 접속할 PC hosts 파일에 Rancher host명 추가
# 윈도우즈 C:\Windows\System32\drivers\etc\hosts
# 10.2.100.100  rancher.kw01
랜처.서버.IP.명  rancher.kw01 # 설치시 등록한 도메인 명 등록
EOF  

2. Install Service Cluster


# 클러스터를 설치할 VM 로그인
# RKE2 설치
$ sudo -i
$ curl -sfL https://get.rke2.io | INSTALL_RKE2_VERSION=v1.24.13+rke2r1 sh -

# 클러스터 구동 확인
$ systemctl enable rke2-server --now &
$ systemctl status -l rke2-server
$ journalctl -fa

# 클러스터 접속 설정

#(Optional) k8sadm 계정 생성
$ groupadd -g 2000 k8sadm
$ useradd -m -u 2000 -g 2000 -s /bin/bash k8sadm
$ echo -e "1\n1" | passwd k8sadm >/dev/null 2>&1
$ echo ' k8sadm ALL=(ALL)   ALL' >> /etc/sudoers

$ su - k8sadm # 사용자 계정
$ mkdir ~/.kube
$ sudo cp /etc/rancher/rke2/rke2.yaml ~/.kube/config
$ sudo chown k8sadm ~/.kube/config
$ sed -i 's/default/rke2-svc/g'  ~/.kube/config

# kubectl cli 설치
$ curl -LO https://dl.k8s.io/release/v1.25.9/bin/linux/amd64/kubectl
$ chmod +x kubectl && sudo mv kubectl /usr/local/bin


3. Rancher에 설치된 클러스터 Import


# 연결할 클러스터 VM 접속

# hosts 파일에 Rancher host명 추가
$ cat <<EOF | sudo tee /etc/hosts
# 10.2.100.100  rancher.kw01
랜처.서버.IP.명  rancher.kw01 argocd.kw01 gitea.kw01 argo.kw01 # 설치시 등록한 도메인 명 등록
EOF

# 복사한 Registration 명령어 실행
$ curl --insecure -sfL https://rancher.kw01/v3/import/vdhpnh5twscr54nbjsjjp7vhjltks6mjr9ppmx25rs4z7blrtzfz4t_c-m-wdghhcjm.yaml | kubectl apply -f -

# host Alias 패치
$ cat <<EOF >> agent-patch.yml
spec:
  template:
    spec:
      hostAliases:
      - ip: 10.2.100.100
        hostnames:
        - rancher.kw01
EOF

$ kubectl patch deployment cattle-cluster-agent --patch-file agent-patch.yml -n cattle-system