Cluster 구성하기

알파로그·2023년 7월 12일
0

Kubernetes

목록 보기
5/15

✏️ Cluster 생성

  • Cluster 는 다수의 서버를 하나로 묶어주는 역할을 한다.
    • Master node 와 worker node 를 설정하는 것 도 Cluster 구성에 포함된다.
  • 참고로 Kubernetes 는 api 통신을 사용해 서버간 통신을 한다.

📍 보안설정

  • 6443 포트의 TCP 프로토콜에 대해 모든 접근을 허용시켜줘야 한다.

📍 cluster 생성

  • Master node 로 정할 서버에 아래의 명령어를 입력하면 된다.
    • domain 이 없다면 공인 ip 로 대체할 수 있다.
      • master 즉, Kubernetes 를 관리하는 API 의 url 이 된다.
    • --pod-network-cidr
      • Kubernetes 로 구성되는 내부 네트워크를 뜻한다.
kubeadm init --control-plane-endpoint "공인HOST:6443" --upload-certs --pod-network-cidr=10.10.0.0/16 -v=5

✏️ Cluster Node 추가하기

📍 Master Node 추가

  • Cluster 생성을 성공하면 성공 메시지에 아래와 같은 명령어 가이드를 확인할 수 있다.
    • 해석해보면 cluster 의 user (node) 를 추가하라는 의미이다.
    • 이미 root 계정으로 작업하고있기 때문에 아래의 명령어로 권한을 설정할 수 있다.
To start using your cluster, you need to run the following as a regular user:

  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf
  • Master node 를 위 명령어로 추가한 다음 Node 목록을 확인하면 Master 노드가 추가된것을 확인할 수 있다.
$ kubectl get nodes -A

NAME     STATUS     ROLES           AGE   VERSION
master   NotReady   control-plane   96m   v1.27.3

📍 Worker Node 추가

  • Cluster 생성 메시지에 조금 더 아래쪽을 살펴보면 worker 를 추가하는 가이드를 확인할 수 있다.
    • 해당명령어에는 Master Node 의 public ip 가 포함되어있다.
    • 아래 코드는 일정시간 후에 만료가 되기 때문에 실행이 되지 않는다면 다시 생성해줘야 한다.
You can now join any number of the control-plane node running the following command on each as root:

  kubeadm join 49.50.160.197:6443 --token z9srxa.l18qywmea20yrjyz \
        --discovery-token-ca-cert-hash sha256:57e47222dd82861b0168b66636af41e8caabaa244219d0728d2f57892e0800cb

📍 node 확인

  • 추가가 완료되면 아래와 같이 노드목록에서 확인할 수 있다.
    • NAME 은 server 의 명칭을 뜻한다.
      • dns 를 변경해 커스텀 할 수 있다.
      • master 노드만 이름을 변경해줫다.
    • ROLES 는 node 의 역할을 의미한다.
      • control-plane 이 master 라는 의미이다.
$ kubectl get nodes

NAME              STATUS     ROLES           AGE    VERSION
ip-172-31-3-203    NotReady   <none>          4m55s   v1.27.3
ip-172-31-42-179   NotReady   <none>          4m7s    v1.27.3
master             NotReady   control-plane   149m    v1.27.3

✏️ Error

📍 token 이 만료된 경우

  • 아래 명령어로 새로운 token 을 발급받고 복사해서 worker node 에 붙여넣기 해주면 된다.
kubeadm token create --print-join-command

📍 Node 추가를 실패한 경우

  • CASE 1
    • 해당 경로에 파일이 없기 때문에 발생한 오류이다.
[ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]:
		/proc/sys/net/bridge/bridge-nf-call-iptables 
		does not exist
  • 아래 명령어를 실행해 bridge 모듈을 로드하고, 값을 1로 설정하면 된다.
modprobe br_netfilter

echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
  • CASE 2
    • ip forward 값이 제대로 설정되지 않은 경우에 발생하는 오류이다.
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: 
		/proc/sys/net/ipv4/ip_forward 
		contents are not set to 1
  • 아래 명령어로 ip 전달을 활성화 하면 해결된다.
sysctl -w net.ipv4.ip_forward=1
  • 변경사항을 저장해준다.
    • 다시 worker node 를 등록하면 정상적으로 등록되는것을 확인할 수 있다.
echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf

📍 쿠버네티스 클러스터 조회 실패

🔗 클러스터 조회 안될 때 해결 방법

✏️ 클러스터 삭제

# y 입력
kubeadm reset

rm -rf $HOME/.kube

rm -rf /etc/cni/net.d

systemctl restart kubelet
profile
잘못된 내용 PR 환영

0개의 댓글