본문 바로가기
DevOps

[Ubuntu]Kubernetes 구성

by Yoon_estar 2024. 8. 9.
728x90
반응형

kubernetes Tools 설치

kubernetes 도구 설치 (1.28)

# curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.28/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

# echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.28/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

# apt update

# apt-cache policy kubeadm
kubeadm:
Installed: (none)
Candidate: 1.28.0-1.1
Version table:
1.28.0-1.1 500
500 https://pkgs.k8s.io/core:/stable:/v1.28/deb Packages

# apt -y install kubelet kubeadm kubectl

 

kubernetes 도구 버전 확인

# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"28", GitVersion:"v1.28.5",
GitCommit:"bae2c62678db2b5053817bc97181fcc2e8388103", GitTreeState:"clean", BuildDate:"2023-11-15T16:56:18Z",
GoVersion:"go1.20.11", Compiler:"gc", Platform:"linux/amd64"}

 

설치된 Kubernetes tool이 자동으로 업데이트 되는 것을 방지해야 하므로 hold 시킨다

# apt-mark hold kubelet kubeadm kubectl
kubelet set on hold.
kubeadm set on hold.
kubectl set on hold.

 

모든 노드에 설치되는 kubelet은 항상 start 상태를 유지해야 하므로 데몬은 enable 시켜준다.

# systemctl daemon-reload
# systemctl restart kubelet.service
# systemctl enable --now kubelet.service

 

클러스터 구축(마스터 노드)

# kubeadm init --pod-network-cidr=10.96.0.0/12 --apiserver-advertise-address=192.168.207.201

 

설치 로그가 쭉 나오고 설치가 완료되면 아래와 같은 문구를 확인 할 수 있다. 쓰여있는데로 복사 붙여넣기하면 된다.

Your Kubernetes control-plane has initialized successfully!

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

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.207.200:6443 --token k4bbtb.aar38u8oafx7m4u0 \
        --discovery-token-ca-cert-hash sha256:45bb08d1c86f8e5ebec7ef8c30d0ebaa647b145568f77e4dc77d0e76dc9521d3

 

위에 로그에 메뉴얼 나옴(마스터노드)

# mkdir -p $HOME/.kube
# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# sudo chown $(id -u):$(id -g) $HOME/.kube/config
# export KUBECONFIG=/etc/kubernetes/admin.conf // 루트 계정에서 적용

 

명령어를 편하게 쓰기 위해 추가 설정(마스터 노드) 해준다. 

apt install bash-completion -y
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
complete -F __start_kubectl k


vi .bashrc

'''
# for examples
alias k=kubectl
alias kg='kubectl get'
alias kc='kubectl create'
alias ka='kubectl apply'
alias kr='kubectl run'
alias kd='kubectl delete'
complete -F __start_kubectl k
'''

source .bashrc

 

클러스터 가입(자식 노드)

kubeadm join 192.168.207.200:6443 --token k4bbtb.aar38u8oafx7m4u0 \
        --discovery-token-ca-cert-hash sha256:45bb08d1c86f8e5ebec7ef8c30d0ebaa647b145568f77e4dc77d0e76dc9521d3

 

마스터 노드에서 확인

root@k8s-master:~# k get no
NAME         STATUS     ROLES           AGE     VERSION
k8s-master   NotReady   control-plane   29m     v1.28.12
k8s-node01   NotReady   <none>          5m9s    v1.28.12
k8s-node02   NotReady   <none>          5m10s   v1.28.12
k8s-node03   NotReady   <none>          5m9s    v1.28.12

 

클러스터 구성을 끝냈고 현재 k get nodes 를 하면 STATUS에서 NotReady 상태이다. 다음 포스팅에서는 Kubernetes DNS 설정을 포스팅 하도록 하겠다.

https://estar987.tistory.com/194

반응형