본문 바로가기

PrivateCloud/Rancher (랜처)

RKE2 RANCHER 설치 with Ubuntu18.04

# RKE2를 설치한다.

1. Cloud9 인스턴스 생성.

2021.10.03 - [⭐ AWS/Cloud9] - Cloud9 생성 및 터미널 접속

 

Cloud9 생성 및 터미널 접속

- cloud9을 검색하여 새로운 환경을 만든다. - 이름과 간단한 설명을 입력 후 다음으로 넘어간다. - 아래 구성과 유사하게 세팅한다. - 생성되고 있는 모습. - 생성이 완료되고 터미널이 활성화된 모

may9noy.tistory.com

2. RKE2 설치 (MasterNode, WorkerNode 공통작업)

# Ubuntu instructions
# stop the software firewall
systemctl stop ufw
systemctl disable ufw

# get updates, install nfs, and apply
apt update
apt install nfs-common -y
apt upgrade -y

# clean up
apt autoremove -y

- RKE2 Install

3. root로 로그인

sudo su -

4. 설치 진행 (마스터노드 생성, 클라우드9이 마스터 노드라면 EIP를 활용하여 고정IP를 연결해준다.)

- 고정 IP를 연결해주지 않으면 마스터노드가 재부팅 될때마다 ip가 변경되므로 워커노의 config.yaml을 매번 변경해줘야 하는 번거로움이 있다. 그래서 마스터노드에는 EIP를 부여하여 연결이 끊어지는것을 방지한다. 

curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=server sh -

# start and enable for restarts -
systemctl enable rke2-server.service
systemctl start rke2-server.service
systemctl status rke2-server.service

5. 설치 확인

systemctl status rke2-server.service

- 정상 설치 확인

6. 심볼릭 링크를 설정 후 kubectl 명령어로 조회를 한다.

# simlink all the things - kubectl
ln -s $(find /var/lib/rancher/rke2/data/ -name kubectl) /usr/local/bin/kubectl
 
# add kubectl conf
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml

# check node status
kubectl  get node

- 조회 결과

kubectl get nodes

NAME            STATUS   ROLES                       AGE   VERSION
ip-10-0-24-88   Ready    control-plane,etcd,master   94m   v1.24.7+rke2r

- 마스터 노드의 설정이 완료 되었다.

- 마스터 노드에서 설정을 확인한다.

# Master Node의 ip 세팅 등 확인 (ip는 ec2 및 cloud9의 public ip 이다.)
/etc/rancher/rke2/rke2.yaml

# Master Node의 토큰값 확인
/var/lib/rancher/rke2/server/node-token

7. Worker node를 만들고 연결하기

- AWS라면 보안그룹에서 9345 포트를 열어 줘야 한다.

# we add INSTALL_RKE2_TYPE=agent
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=agent sh -

# create config file
mkdir -p /etc/rancher/rke2/

# change the ip to reflect your rancher1 ip
# 마스터 노드의 public_ip를 넣어준다.
echo "server: https://$RANCHER1_IP:9345" > /etc/rancher/rke2/config.yaml

# change the Token to the one from rancher1 /var/lib/rancher/rke2/server/node-token
# 마스터 노드의 토큰 값을 넣어준다.
echo "token: $TOKEN" >> /etc/rancher/rke2/config.yaml

# enable and start
systemctl enable rke2-agent.service
systemctl start rke2-agent.service

8. 마스터 노드에서 워커노드의 참여 확인

- 노드가 2개로 늘어난 것을 확인할 수 있다. 1개는 마스터노드이고 1개는 워커노드 이다.

kubectl get node -o wide -w

NAME             STATUS   ROLES                       AGE    VERSION          INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
ip-10-0-12-182   Ready    <none>                      3m6s   v1.24.7+rke2r1   10.0.12.182   <none>        Ubuntu 18.04.6 LTS   5.4.0-1088-aws   containerd://1.6.8-k3s1
ip-10-0-24-88    Ready    control-plane,etcd,master   154m   v1.24.7+rke2r1   10.0.24.88    <none>        Ubuntu 18.04.6 LTS   5.4.0-1088-aws   containerd://1.6.8-k3s1

- 이제 클라우드9에서 노드 1개를 추가로 생성하여 워커노드 1개를 추가로 연결한다.

- 방식은 7번과 같은 방식이다.

# we add INSTALL_RKE2_TYPE=agent
curl -sfL https://get.rke2.io | INSTALL_RKE2_TYPE=agent sh -

# create config file
mkdir -p /etc/rancher/rke2/

# change the ip to reflect your rancher1 ip
# 마스터 노드의 public_ip를 넣어준다.
echo "server: https://$RANCHER1_IP:9345" > /etc/rancher/rke2/config.yaml

# change the Token to the one from rancher1 /var/lib/rancher/rke2/server/node-token
# 마스터 노드의 토큰 값을 넣어준다.
echo "token: $TOKEN" >> /etc/rancher/rke2/config.yaml

# enable and start
systemctl enable rke2-agent.service
systemctl start rke2-agent.service
systemctl status rke2-agent.service

- 워커노드 2번 등록 확인, 1개의 워커노드가 추가로 등록된것을 확인 할 수 있다.

kubectl get node -o wide

NAME             STATUS     ROLES                       AGE    VERSION          INTERNAL-IP   EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION   CONTAINER-RUNTIME
ip-10-0-10-113   NotReady   <none>                      7s     v1.24.7+rke2r1   10.0.10.113   <none>        Ubuntu 18.04.6 LTS   5.4.0-1088-aws   containerd://1.6.8-k3s1
ip-10-0-12-182   Ready      <none>                      16m    v1.24.7+rke2r1   10.0.12.182   <none>        Ubuntu 18.04.6 LTS   5.4.0-1088-aws   containerd://1.6.8-k3s1
ip-10-0-24-88    Ready      control-plane,etcd,master   168m   v1.24.7+rke2r1   10.0.24.88    <none>        Ubuntu 18.04.6 LTS   5.4.0-1088-aws   containerd://1.6.8-k3s1

9. 지금까지 구성내용 확인

Rancher_Master_Worker.drawio
0.00MB

- 다음은 Helm을 활용하여 RANCHER 대쉬보드를 설치하는 작업을 진행한다.

- 만약 Master Node를 이중화로 생성하려면 위의 INSTALL_RKE2_TYPE=agent sh - 를 server, agent를 정해서 설치를 진행하면 된다.

 

참고 사이트

https://ranchergovernment.com/simple-rke2-longhorn-and-rancher-install#prerequisites

 

Simple RKE2, Longhorn, and Rancher Install – RGS

Simple RKE2, Longhorn, and Rancher Install – RGS

ranchergovernment.com