쿠버네티스 설치
✔ 사전 조건
: 서버 기본 3개 구성
- Master
- Node1
- Node2
Ubuntu에 설치
- Ubuntu 22.04
- 2 core 4 GiB memory
1. Kubeadm 설치
❔ Kubeadm이란
kubeadm은 쿠버네티스에서 제공하는 기본적인 도구로
클러스터를 빠르고 쉽게 구축하기 위한 기능 제공
1-1. 환경 구성
/etc/hosts
sudo vi /etc/hosts
~
127.0.0.1 hosts
[master private ip] master
[node1 private ip] node1
[node2 private ip] node2
~
1-2. 도커 & 도커 엔진 설치
1️⃣ 도커
Install Docker Engine on Ubuntu
docs.docker.com
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
sudo apt-get install docker.io -y
2️⃣ 도커 엔진
Release v0.2.6 · Mirantis/cri-dockerd
What's Changed Bump docker client to 20.10 and use StatsOneShot to get stats by @cpuguy83 in #107 Use context.WithCancel for potentially long operations by @evol262 in #108 Make the bind address f...
github.com
wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.2.6/cri-dockerd_0.2.6.3-0.ubuntu-bionic_amd64.deb
sudo dpkg -i cri-dockerd_0.2.6.3-0.ubuntu-bionic_amd64.deb
1-3. kubeadm, kubelet and kubectl 설치
# bridge traffic 활성화
# br_netfilter 모듈을 로드
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
modprobe overlay
modprobe br_netfilter
# bridge taffic 보게 커널 파라메터 수정
# 필요한 sysctl 파라미터를 /etc/sysctl.d/conf 파일에 설정하면, 재부팅 후에도 값이 유지된다.
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
# 재부팅하지 않고 sysctl 파라미터 적용하기
sysctl --system
# kubelet and kubectl 설치
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
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
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
2. 클러스터 생성
2-1. K8s 설치
control-plain = initializing your
control-plane no
2-2. Master서버 토큰 발급
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
Installing Addons
Note: This section links to third party projects that provide functionality required by Kubernetes. The Kubernetes project authors aren't responsible for these projects, which are listed alphabetically. To add a project to this list, read the content guide
kubernetes.io
# control-plaine 컴포넌트 구성
kubeadm init --pod-network-cidr=192.168.0.0/16 --cri-socket unix:///var/run/cri-dockerd.sock
...
[addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully!
# Kubectl을 명령 실행 허용하려면 kubeadm init 명령의 실행결과 나온 내용을 동작해야 함
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
# root 권한으로 worker node join을 위한 명령어. 별도 저장해둠. (워커노드 조인할 때 사용)
cat > token.join
(토큰정보) --cri-sockert unix:///var/run/cri-dockerd.sock
<CTRL>+<d>
# CNI(컨테이너 네트워크 인터페이스) 기반 Pod 네트워크 추가 기능을 배포해야 Pod가 서로 통신할 수 있습니다. 네트워크를 설치하기 전에 클러스터 DNS(CoreDNS)가 시작되지 않습니다.
kubectl get nodes
NAME STATUS ROLES AGE VERSION
master NotReady control-plane 7m31s v1.24.3
2-3. 칼리코 설치
❔ 칼리코란
가상머신이나 컨테이너를 위한 네트워킹, IP 관리, 접근 제어, 모니터링 등 다양한 네트워크 관련 기능을 제공
k8s에서 각 Node에 설치되어 각 Pod간 네트워크 통신이 가능하도록 도와줌
Quickstart for Calico on Kubernetes | Calico Documentation
Install Calico on a single-host Kubernetes cluster for testing or development in under 15 minutes.
docs.tigera.io
# Pod 네트워크가 호스트 네트워크와 겹치지 않도록 주의해야함.
# Calico 설치
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.3/manifests/tigera-operator.yaml
kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.24.3/manifests/custom-resources.yaml
# node 초기화 될때까지 기다림
watch kubectl get pods -n calico-system
kubectl get pods -n calico-system
NAME READY STATUS RESTARTS AGE
calico-kube-controllers-657d56796-nrxbx 0/1 Pending 0 75s
calico-node-w2n8f 1/1 Running 0 75s
calico-typha-5d9f7ffbf4-mx846 1/1 Running 0 75s
# 다시 확인
kubectl get nodes
NAME STATUS ROLES AGE VERSION
master.example.com Ready control-plane 15m v1.24.3
curl -L https://github.com/projectcalico/calico/releases/download/v3.24.3/calicoctl-linux-amd64 -o calicoctl
chmod +x calicoctl
mv calicoctl /usr/bin
calicoctl apply -f ipipmode.yaml
calicoctl get ippool -o wide
cat << END > ipipmode.yaml
apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
name: default-ipv4-ippool
spec:
blockSize: 26
cidr: 192.168.0.0/16
ipipMode: Always
natOutgoing: true
nodeSelector: all()
vxlanMode: Never
END
calicoctl apply -f ipipmode.yaml
calicoctl get ippool -o wide
kubectl get pods -A
3. Node 조인
마스터와 워커노드 조인
[master]
cat token.join
(내용복사)
[node1]
sudo (붙여넣기)
[node2]
sudo (붙여넣기)
4. 쿠버네티스 기본 구성
kubectl 명령어 자동 완성 설정
kubectl Cheat Sheet
This page contains a list of commonly used kubectl commands and flags. Kubectl autocomplete BASH source <(kubectl completion bash) # set up autocomplete in bash into the current shell, bash-completion package should be installed first. echo "source <(kubec
kubernetes.io
sudo apt-get install bash-completion -y
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
user 사용자가 kubectl 명령을 실행 할 수 있도록 설정
mkdir -p ~ubuntu/.kube
sudo cp -i /etc/kubernetes/admin.conf ~ubuntu/.kube/config
chown ubuntu:ubuntu ~ubuntu/.kube/config
exit
kubectl get node
참조
https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
'🐳 Container > K8S' 카테고리의 다른 글
[K8s] 쿠버네티스(Kubernetes) 컨트롤러 (1) (0) | 2023.03.27 |
---|---|
[K8s] 쿠버네티스(Kubernetes) 레이블(Labels) (0) | 2023.03.27 |
[K8s] 쿠버네티스(Kubernetes) pod 관리 (0) | 2023.03.26 |
[K8s] 쿠버네티스(Kubernetes) node 관리 (0) | 2023.03.26 |
[K8s] 쿠버네티스(Kubernetes)의 이해 (1) | 2023.03.23 |