클라우드 + DevOps/Kubernetes (k8s)

Kubernetes :: Master 서버와 Node 연결

gamjadori 2024. 4. 25. 16:58
728x90

<Kubernetes :: Master 서버와 Node 연결>

  • 실습 진행 중, node를 삭제하는 과정을 거쳐 초기화 후 node를 재설정하는 과정 실행

<Master 서버 작업>

1. Kubernetes 클러스터 재설정 명령

ubuntu@k8s-master:~$ sudo kubeadm reset

 

2. Kubernetes 클러스터 초기화 / 마스터 노드의 설정 및 구성 수행

ubuntu@k8s-master:~$ sudo kubeadm init --pod-network-cidr=10.96.0.0/12 --apiserver-advertise-address=192.168.56.100

<출력 결과>

 

3. 노드 조인 작업

A. k8s-node1 작업

  • ssh ubuntu@k8s-node1 명령어를 통해 SSH 접속
ubuntu@k8s-node1:~$ sudo kubeadm reset
W0222 13:46:22.300364  113274 preflight.go:56] [reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y

ubuntu@k8s-node1:~$ sudo kubeadm join 192.168.56.100:6443 --token 1c050c.381jylyradwx3d6h \
        --discovery-token-ca-cert-hash sha256:c7001bcd595a0929df38cb89e1193a90a5cb96c436ba00c6de26bb52cc449c3a

 

B. k8s-node3 작업

  • ssh ubuntu@k8s-node3 명령어를 통해 SSH 접속
ubuntu@k8s-node3:~$ sudo kubeadm reset
W0222 13:46:22.300364  113274 preflight.go:56] [reset] WARNING: Changes made to this host by 'kubeadm init' or 'kubeadm join' will be reverted.
[reset] Are you sure you want to proceed? [y/N]: y

ubuntu@k8s-node3:~$ sudo kubeadm join 192.168.56.100:6443 --token 1c050c.381jylyradwx3d6h \
        --discovery-token-ca-cert-hash sha256:c7001bcd595a0929df38cb89e1193a90a5cb96c436ba00c6de26bb52cc449c3a

 

4. Master 서버 작업

  • 관리자 권한으로 클러스터에 접근할 수 있는 Kubernetes 구성 파일이 사용자의 홈 디렉토리에 설정
ubuntu@k8s-master:~$ sudo cp /etc/kubernestes/admin.conf ~/.kube/config

 

5. 노드 등록 확인

ubuntu@k8s-master:/etc/kubernetes$ kubectl get nodes
NAME         STATUS   ROLES           AGE   VERSION
k8s-master   Ready    control-plane   75m   v1.28.7
k8s-node1    Ready    <none>          69m   v1.28.7
k8s-node3    Ready    <none>          9s    v1.28.7

 

6. 추가 네트워크 설정

  • BusyBox: 리눅스용 경량 유틸리티 및 셸을 제공하는 소프트웨어
ubuntu@k8s-master:~$ docker pull busybox:latest
latest: Pulling from library/busybox
9ad63333ebc9: Pull complete 
Digest: sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74
Status: Downloaded newer image for busybox:latest
docker.io/library/busybox:latest

 

<calico.yaml 파일 확인>

ubuntu@k8s-master:~$ ls
2163         cd              Desktop    Downloads   Music     Public  snap       Videos
calico.yaml  dashboard_rbac  Documents  monitoring  Pictures  pwd     Templates

 

7. Kubernetes 리소스를 클러스터에 적용 (네트워크 정책 설정)

ubuntu@k8s-master:~$ kubectl apply -f calico.yaml