카이도스의 Tech Blog

쿠버네티스 kubespray 설치 본문

KOPS

쿠버네티스 kubespray 설치

카이도스 2023. 3. 14. 13:14
728x90
반응형

vm 활용해서 쿠버네티스 설치를 진행.

설치환경 - ubuntu 20.04 - 테스트서버(10.10.13.133/134)/k8s


# vm 생성 후 호스트네임 변경
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2

reboot

# 호스트 네임 설정
vi /etc/hosts
10.10.13.133 k8s-master
10.10.13.134 k8s-node1
10.10.13.135 k8s-node2

# 방화벽 끄기
sudo ufw disable

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

# 설정
sudo sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
cat /proc/sys/net/ipv4/ip_forward
1

# ssh keygen 생성
# 기본설정으로 옵션을 추가하지 않고 계속 엔터만 입력
ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa
Your public key has been saved in /root/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:Dd+x4vn89x6BRglFQko/lLLFZG4YJ1A1h2iXHcLyPVo root@k8s-master
....

# 키 복사
ssh-copy-id k8s-master
ssh-copy-id k8s-node1
ssh-copy-id k8s-node2


# 마스터 노드에서 진행
git clone https://github.com/kubernetes-sigs/kubespray.git
apt update && apt upgrade -y
apt install -y python3-pip
pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

cd kubespray/
sudo pip3 install -r requirements.txt

# 내려받은 소스파일 중 inventory/sample 전체를 inventory/mycluster로 복사
cp -rfp inventory/sample inventory/mycluster

cd /root/kubespray/inventory/mycluster
vi inventory.ini
----------------
[all]
k8s-master ansible_host=10.10.13.133 ip=10.10.13.133
k8s-node1 ansible_host=10.10.13.134 ip=10.10.13.134
k8s-node2 ansible_host=10.10.13.135 ip=10.10.13.135

[kube_control_plane]
k8s-master

[etcd]
k8s-master

[kube_node]
k8s-master
k8s-node1
k8s-node2

[calico_rr]

[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr
----------------

# 플레이북 실행
cd ~/kubespray/
ansible all -m ping -i inventory/mycluster/inventory.ini
ansible-playbook -i inventory/mycluster/inventory.ini cluster.yml -b

#삭제
ansible-playbook -i inventory/mycluster/hosts.yml --become --become-user=root -v reset.yml
#10~16분정도 걸림
......
Monday 13 February 2023  05:54:36 +0000 (0:00:00.083)       0:10:37.826 *******
......

# 확인
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   5m19s   v1.26.1   10.10.13.133   <none>        Ubuntu 20.04.5 LTS   5.4.0-139-generic   containerd://1.6.16
k8s-node1    Ready    control-plane   4m41s   v1.26.1   10.10.13.134   <none>        Ubuntu 20.04.5 LTS   5.4.0-139-generic   containerd://1.6.16
k8s-node2    Ready    control-plane   4m23s   v1.26.1   10.10.13.135   <none>        Ubuntu 20.04.5 LTS   5.4.0-139-generic   containerd://1.6.16


# Helm 설치
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
helm version
version.BuildInfo{Version:"v3.11.1", GitCommit:"293b50c65d4d56187cd4e2f390f0ada46b4c4737", GitTreeState:"clean", GoVersion:"go1.18.10"}


# 환경변수
kubectl completion bash | sudo tee /etc/bash_completion.d/kubectl > /dev/null
echo "alias k=kubectl" >> ~/.bashrc
echo "complete -o default -F __start_kubectl k" >> ~/.bashrc
exec bash
k version --short
728x90
반응형
Comments