본문 바로가기
DevOps/Kubernetes

[Kubernetes] etcd 데몬 설정 및 문제해결

by Yoon_estar 2025. 3. 18.
728x90

🔹 개요

Kubernetes 클러스터를 운영할 때, etcd는 핵심 데이터 저장소 역할을 합니다. etcd가 정상적으로 동작하지 않으면 API 서버도 정상적으로 작동하지 않으며, kubectl 명령어를 실행할 때 etcdserver: request timed out 오류가 발생할 수 있습니다.

이 글에서는 etcd를 데몬(service)으로 설정하는 방법과, 실행되지 않을 때의 문제 해결 과정을 정리합니다.

 

✅ etcd 데몬 설정 방법

etcd 바이너리 다운로드 및 설치

export ETCD_VERSION=v3.5.9
curl -LO https://github.com/etcd-io/etcd/releases/download/${ETCD_VERSION}/etcd-${ETCD_VERSION}-linux-amd64.tar.gz

 

압축 해제 및 실행 파일 이동

tar xvf etcd-${ETCD_VERSION}-linux-amd64.tar.gz
sudo mv etcd-${ETCD_VERSION}-linux-amd64/etcd* /usr/local/bin/
rm -rf etcd-${ETCD_VERSION}-linux-amd64*

 

etcd 서비스 유닛 파일 생성

  • control-plane 마다 ip 맞게 세팅해야함
      --name kube-master-210 \
      --listen-client-urls=https://192.168.207.210:2379 \
      --advertise-client-urls=https://192.168.207.210:2379 \
      --listen-peer-urls=https://192.168.207.210:2380 \
      --initial-advertise-peer-urls=https://192.168.207.210:2380 \
# vi /etc/systemd/system/etcd.service

[Unit]
Description=etcd key-value store
Documentation=https://github.com/etcd-io/etcd
After=network.target

[Service]
ExecStart=/usr/local/bin/etcd \
  --name=kube-master-200 \
  --data-dir=/var/lib/etcd \
  --listen-client-urls=https://192.168.207.200:2379 \
  --advertise-client-urls=https://192.168.207.200:2379 \
  --listen-peer-urls=https://192.168.207.200:2380 \
  --initial-advertise-peer-urls=https://192.168.207.200:2380 \
  --initial-cluster=kube-master-200=https://192.168.207.200:2380,kube-master-210=https://192.168.207.210:2380,kube-master-220=https://192.168.207.220:2380 \
  --initial-cluster-token etcd-cluster-0 \
  --initial-cluster-state new \
  --client-cert-auth \
  --trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt \
  --cert-file=/etc/kubernetes/pki/etcd/server.crt \
  --key-file=/etc/kubernetes/pki/etcd/server.key \
  --peer-cert-file=/etc/kubernetes/pki/etcd/peer.crt \
  --peer-key-file=/etc/kubernetes/pki/etcd/peer.key \
  --peer-client-cert-auth \
  --peer-trusted-ca-file=/etc/kubernetes/pki/etcd/ca.crt

Restart=always
RestartSec=5

[Install]
WantedBy=multi-user.target

 

서비스 파일 인식하도록 재로드 및 서비스 활성화

# sudo systemctl daemon-reload
# sudo systemctl enable etcd
# sudo systemctl start etcd
# systemctl status etcd

 

❗ etcd 실행 실패 시 문제 해결

1️⃣ bind: address already in use 오류 해결

에러 로그 :

"error":"listen tcp 192.168.207.200:2380: bind: address already in use"

 

해결 방법 : 

출력된 프로세스를 종료

# netstat -tulnp | grep 2380
# kill -9 17330

 

프로세스 재시작

# systemctl start etcd
# systemctl status etcd

 

네임 스페이스 조회

정상 작동 확인

# kubectl get ns
NAME              STATUS   AGE
default           Active   11d
kube-node-lease   Active   11d
kube-public       Active   11d
kube-system       Active   11d