Docker & Kubernetes/쿠버네티스

ubuntu에 쿠버네티스 설치하는 방법

miracle21 2024. 12. 2. 11:04
반응형

 

0. 설치 전 확인사항

  • 호환되는 리눅스 머신. 쿠버네티스 프로젝트는 데비안 기반 배포판, 레드햇 기반 배포판, 그리고 패키지 매니저를 사용하지 않는 경우에 대한 일반적인 가이드를 제공한다.
  • 2 GB 이상의 램을 장착한 머신. (이 보다 작으면 사용자의 앱을 위한 공간이 거의 남지 않음)
  • 2 이상의 CPU.
  • 클러스터의 모든 머신에 걸친 전체 네트워크 연결. (공용 또는 사설 네트워크면 괜찮음)
  • 모든 노드에 대해 고유한 호스트 이름, MAC 주소 및 product_uuid. 자세한 내용은 여기를 참고한다.
  • 컴퓨터의 특정 포트들 개방. 자세한 내용은 여기를 참고한다.
  • 스왑의 비활성화. kubelet이 제대로 작동하게 하려면 반드시 스왑을 사용하지 않도록 설정한다.

 

1. VM서버 구성

 

서버 설정

 

만약 너무 과도하게 리소스를 할당하면 로컬에서 메모리를 너무 잡아먹을 수 있다.

 

그러면 API connection 문제가 발생해서 cluster 내의 통신 오류가 생길 수 있으니 본인 로컬에 맞게 할당하자.

 

name IP system
mater 10.0.2.10 Ubuntu22.04, 2Core3G
worker-1 10.0.2.20 Ubuntu22.04, 2Core3G

 

 

Swap 사용중지

swapoff -a && sudo sed -i '/swap/d' /etc/fstab

 

 

Linux 노드의 iptables가 bridged traffic을 정확하게 확인하고 제어 할 수 있도록 br_netfilter 모듈을 load하고 관련된 네트워크 파라미터를 설정

modprobe overlay
modprobe br_netfilter

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system

 

 

2. 컨테이너 런타임 설치

 

containerd, CRI-O , docker engine 이 세 가지를 많이 언급하는데

 

docker engine은 더이상 컨테이너 런타임으로 사용하기는 어려워서 cri-o로 설치하려고 한다.

 

설치는 공식문서를 봐도 충분히 설치 가능하며, kubeadm, kubelet, kubectl 까지 한번에 설치할 수 있다.

 

 

 

https://github.com/cri-o/packaging/blob/main/README.md#usage

 

packaging/README.md at main · cri-o/packaging

CRI-O deb and rpm packages. Contribute to cri-o/packaging development by creating an account on GitHub.

github.com

 

 

이전에 cri-o 설치에 대해 포스팅한 내용을 참고해도 된다.

 

 

 

3. Control-plane에 cluster 설치

 

아래 공식문서에서 Initializing your control-plane node 부분 참고해서 설치

 

https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/

 

Creating a cluster with kubeadm

Using kubeadm, you can create a minimum viable Kubernetes cluster that conforms to best practices. In fact, you can use kubeadm to set up a cluster that will pass the Kubernetes Conformance tests. kubeadm also supports other cluster lifecycle functions, su

kubernetes.io

 

 

kubeadm init
 

 

init 이후에 control-plane에서 설정해야 할 코드 몇 줄과, worker node에서 해야 할 cluster join 명령어가 뜬다

 

 

4. Control-plane에 CNI 설치

weave나 calico 중에 용도에 적합한 CNI를 선택한다. 둘 다 설치해봤는데 정상적으로 작동한다.

 

Weave Net

https://github.com/rajch/weave#using-weave-on-kubernetes

 

GitHub - rajch/weave: Simple, resilient multi-host containers networking and more.

Simple, resilient multi-host containers networking and more. - rajch/weave

github.com

 

Calico

https://docs.tigera.io/calico/latest/getting-started/kubernetes/self-managed-onprem/onpremises

 

Install Calico networking and network policy for on-premises deployments | Calico Documentation

Install Calico networking and network policy for on-premises deployments.

docs.tigera.io

 

 

 

5. Worker node에 join

 
3번 cluster 설치 후 나타난 join 명령어를 worker node에 실행
 
 
 

6. node간 통신 확인

 

아래 링크를 참고해서 dnsutil 테스트.

 

https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

 

Debugging DNS Resolution

This page provides hints on diagnosing DNS problems. Before you begin You need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. It is recommended to run this tutorial on a cluster with at

kubernetes.io

 

 

kubectl apply -f https://k8s.io/examples/admin/dns/dnsutils.yaml
kubectl exec -i -t dnsutils -- nslookup kubernetes.default

 

 
만약 아래처럼 통신이 확인 안된다면
 
Server:    10.0.0.10
Address 1: 10.0.0.10

Name:      kubernetes.default
Address 1: 10.0.0.1
 
coreDNS를 업데이트해본다.
kubectl rollout restart deployment coredns -n kube-system
 

 

 

7. 그 외 세팅

 

node에 label 붙이기

# kubectl label node [노드명] node-role.kubernetes.io/[ROLES]'="[LABEL]"
kubectl label node worker node-role.kubernetes.io/node="node

 

 

kubectl 을 k 로 축약

echo "alias k='kubectl'" >> ~/.bashrc
source ~/.bashrc

 

반응형