07-bootstrapping-etcd

Dante·2024년 6월 2일
0

kubernetes-hard-way

목록 보기
8/13

Bootstrapping the etcd Cluster


Kubernetes 컴포넌트들은 상태비저장(stateless)이며 클러스터 정보들은 etcd 에 저장합니다.

이번 랩에서는 controlplane-1 서버에 etcd 를 부트스트랩하는 과정을 진행합니다.

etcd 는 고가용성을 위해 3대 이상 서버를 준비하는것을 권장하지만, 이번 튜토리얼은 1대로 진행됩니다.

https://etcd.io/docs/v3.5/faq/ 공식 사이트에서 확인하실 수 있습니다.

Prerequstites



mkdir /k8s-hardway/units/
ETCD_NAME=controlplane-1

cat > /k8s-hardway/units/etcd.service <<EOF
[Unit]
Description=etcd
Documentation=https://github.com/etcd-io/etcd

[Service]
Type=notify
ExecStart=/usr/local/bin/etcd \\
  --name ${ETCD_NAME} \\
  --initial-advertise-peer-urls http://127.0.0.1:2380 \\
  --listen-peer-urls http://127.0.0.1:2380 \\
  --listen-client-urls http://127.0.0.1:2379 \\
  --advertise-client-urls http://127.0.0.1:2379 \\
  --initial-cluster-token etcd-cluster-0 \\
  --initial-cluster controlplane-1=http://127.0.0.1:2380 \\
  --initial-cluster-state new \\
  --data-dir=/var/lib/etcd
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
EOF

controlplane-1 서버에 etcd 실행파일과 systemd unit 파일을 복사합니다.

scp \
  /k8s-hardway/downloads/etcd-v3.5.13-linux-amd64.tar.gz \
  /k8s-hardway/units/etcd.service \
  root@controlplane-1:~/

이번 실습은 controlplane-1 서버에서 작업해야 합니다. SSH를 이용해 해당 서버에 접근합ㄴ디ㅏ.

ssh root@controlplane-1

Bootstrapping an etcd Cluster


Install the etcd Binaries

etcd 압축 파일을 풀고 관련 파일들을 /usr/local/bin 디렉터리에 옮깁니다.

{
  tar -xvf etcd-v3.5.13-linux-amd64.tar.gz
  mv etcd-v3.5.13-linux-amd64/etcd* /usr/local/bin/
} 

Configure the etcd Server

{
  mkdir -p /etc/etcd /var/lib/etcd
  chmod 700 /var/lib/etcd
  cp ca.crt \
    /etc/etcd/
}

etcd 멤버는 etcd cluster 내에 고유한 이름을 가져야합니다. 현재 이 서버의 hostname과 etcd에 설정한 hostname이 동일한지 확인이 필요합니다.

 grep `hostname` etcd.service
  --name controlplane-1 \
  --initial-cluster controlplane-1=http://127.0.0.1:2380 \

etcd를 데몬으로 실행하기 위해 /etc/systemd/system/ 디렉터리에 systemd unit 파일을 옮깁니다.

mv etcd.service /etc/systemd/system/

Start the etcd Server

etcd 서버를 실행합니다.

{
  systemctl daemon-reload
  systemctl enable etcd
  systemctl start etcd
}

Vertification


etcd 서버가 잘 동작하는지 확인합니다.

systemctl status etcd
● etcd.service - etcd
     Loaded: loaded (/etc/systemd/system/etcd.service; enabled; vendor preset: >
     Active: active (running) since Wed 2024-05-29 07:33:31 UTC; 8s ago
       Docs: https://github.com/etcd-io/etcd
   Main PID: 4970 (etcd)
      Tasks: 9 (limit: 9389)
     Memory: 6.7M
        CPU: 44ms
     CGroup: /system.slice/etcd.service
             └─4970 /usr/local/bin/etcd --name controlplane-1 --initial-adverti>

etcd 클러스터 멤버를 확인합니다.

etcdctl member list
6702b0a34e2cfd39, started, controlplane-1, http://127.0.0.1:2380, http://127.0.0.1:2379, false

Next: Bootstrapping the Kubernetes Control Plane

profile
it's me.

0개의 댓글

관련 채용 정보