728x90
반응형
우분투 18.04 서버에 쿠버네티스 클러스터 환경(master, worker-node1, worker-node2) 구성하는 방법에 대해 알아보자.
우분투 18.04 서버가 3대 준비되어 있는 상태에서 시작한다.
1. Docker 설치(모든 서버에 설치)
repository를 이용한 설치(참고 URL)
1) Set up the repository
# Update the apt package index and install packages to allow apt to use a repository over HTTPS:
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
# Add Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
# Use the following command to set up the repository:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
2) Install Docker Engine
# Update the apt package index:
sudo apt-get update
# GPG 에러가 발생하는 경우
sudo chmod a+r /etc/apt/keyrings/docker.gpg
sudo apt-get update
# Install Docker Engine, containerd, and Docker Compose.
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# Verify that the Docker Engine installation is successful by running the hello-world image:
sudo docker run hello-world
2. Kubernetes 설치(모든 서버에 설치)
repository를 이용한 설치(참고 URL)
1) 설치 전 환경설정
# Swap disabled
swapoff -a && sed -i '/swap/s/^/#/' /etc/fstab
# Letting iptables see bridged traffic
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
# Disable firewall
systemctl stop firewalld
systemctl disable firewalld
2) kubeadm, kubelet 및 kubectl 설치
# apt 패키지 색인을 업데이트하고, 쿠버네티스 apt 리포지터리를 사용하는 데 필요한 패키지를 설치
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
# 구글 클라우드의 공개 사이닝 키를 다운로드
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
# 쿠버네티스 apt 리포지터리를 추가
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
# apt 패키지 색인을 업데이트하고, kubelet, kubeadm, kubectl을 설치하고 해당 버전을 고정
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
3. control-plane 구성 (master 노드에서만 설정)
1) kubeadm init
kubeadm init
~~~~~~~~~~~
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.137.10:6443 --token hj6hei.zlz3v0531x9jjyqs \
--discovery-token-ca-cert-hash sha256:4d1b431f15995807ac22cb1f7dc4f6d1d2004e271a3c24a8bdb928e8536cb703
# 일반계정에서도 k8s 를 사용하려면 일반계정으로 접속 후 아래 명령어 입력
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# root 에서 k8s 를 사용하려면 아래 명령어 입력
export KUBECONFIG=/etc/kubernetes/admin.conf
# kubeadm join 관련 메시지는 따로 저장
- kubeadm init 에러 발생 시
# 아래 오류가 발생하는 경우
[init] Using Kubernetes version: v1.26.0
[preflight] Running pre-flight checks
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR CRI]: container runtime is not running: output: E0108 06:35:18.830142 12240 remote_runtime.go:948] "Status from runtime service failed" err="rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
time="2023-01-08T06:35:18Z" level=fatal msg="getting status of runtime: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
, error: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
# 아래 명령어 실행 후 다시 kubeadm init 실행
rm /etc/containerd/config.toml
systemctl restart containerd
2) Pod network add-on
# Weave Net 설치
kubectl apply -f "https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml"
- 설치 후 상태 확인
kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready control-plane 24m v1.26.0
- kubectl 뒤에 명령어 자동 완성을 위한 설정
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
4. worker node 구성(worker 노드에서만 설정)
1) worker node join
# kubeadm init 출력 메시지로 나온 join 관련 명령어 입력
kubeadm join 192.168.137.10:6443 --token hj6hei.zlz3v0531x9jjyqs --discovery-token-ca-cert-hash sha256:4d1b431f15995807ac22cb1f7dc4f6d1d2004e271a3c24a8bdb928e8536cb703
# join 결과 확인
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane 31m v1.26.0 192.168.137.10 <none> Ubuntu 18.04.6 LTS 4.15.0-156-generic containerd://1.6.14
k8s-node1 Ready <none> 108s v1.26.0 192.168.137.11 <none> Ubuntu 18.04.6 LTS 4.15.0-156-generic containerd://1.6.14
k8s-node2 Ready <none> 81s v1.26.0 192.168.137.12 <none> Ubuntu 18.04.6 LTS 4.15.0-156-generic containerd://1.6.14
이제 원하는 pod를 실행하면 된다.
끝~!
728x90
반응형
'IT > etc' 카테고리의 다른 글
쿠버네티스 context - kubectl 로 멀티 클러스터 접근하기 (0) | 2023.01.14 |
---|---|
크롬에서 웹 페이지 전체 캡처 방법 (0) | 2022.12.04 |
댓글