Kubespray로 Kubernetes 설치

김효진·2022년 6월 9일
0

k8s2에서 작업.

1. kubespray를 이용해 kubernetes를 설치하기 위해 kubespray git을 클론.

kubespray 클론

$ git clone https://github.com/kubernetes-sigs/kubespray.git
$ cd kubespray # 원활한 작업을 위해 디렉토리 이동

2. kubespray실행을 위한 python 라이브러리 설치

python3, pip3 설치

$ sudo apt update
$ sudo apt install python3
$ python3 --version
Python 3.8.10

$ sudo apt install python3-pip
$ pip3 --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)

python라이브러리 설치

$ sudo pip3 install -r requirements.txt

설치될 파일 목록들은 다음과 같다.
requirements.txt

ansible==5.7.1
ansible-core==2.12.5
cryptography==3.4.8
jinja2==2.11.3
netaddr==0.7.19
pbr==5.4.4
jmespath==0.9.5
ruamel.yaml==0.16.10
ruamel.yaml.clib==0.2.6
MarkupSafe==1.1.1

3. Asible 실행을 위한 inventory 설정

샘플 파일 복사

$ cp -rfp inventory/sample inventory/mycluster

기본 인벤토리 설정

ansible.cfg

...
[defaults]
inventory = inventory/mycluster/inventory.ini
...

Managed node(Host) 추가

inventory/mycluster/inventory.ini

# ## Configure 'ip' variable to bind kubernetes services on a
# ## different ip than the default iface
# ## We should set etcd_member_name for etcd cluster. The node that is not a etcd member do not need to set the value, or can set the empty string value.
[all]
k8s2 ansible_host=192.168.56.51  ip=192.168.56.51
k8s3 ansible_host=192.168.56.52  ip=192.168.56.52

[kube_control_plane]
k8s2

[etcd]
k8s2

[kube_node]
k8s2
k8s3

[calico_rr]

[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr

4. Kubespray를 위한 Ansible용 SSH Key 생성 및 배포

SSH Key 생성

$ ssh-keygen

SSH Key 배포

$ ssh-copy-id vagrant@192.168.56.51
$ ssh-copy-id vagrant@192.168.56.52

5. Kubernetes Cluster 생성

ansible-playbook cluster.yml -b

6. Kubernetes 설치 확인

k8s2 VM 에서 명령어 실행

context 추가

mkdir ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
sudo chown vagrant:vagrant ~/.kube/config

Kubectl 명령어로 설치 확인

kubectl get pods -A

참고: https://github.com/kubernetes-sigs/kubespray

0개의 댓글