k8s2에서 작업.
kubespray 클론
$ git clone https://github.com/kubernetes-sigs/kubespray.git
$ cd kubespray # 원활한 작업을 위해 디렉토리 이동
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
샘플 파일 복사
$ 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
SSH Key 생성
$ ssh-keygen
SSH Key 배포
$ ssh-copy-id vagrant@192.168.56.51
$ ssh-copy-id vagrant@192.168.56.52
ansible-playbook cluster.yml -b
k8s2 VM 에서 명령어 실행
context 추가
mkdir ~/.kube
sudo cp /etc/kubernetes/admin.conf ~/.kube/config
sudo chown vagrant:vagrant ~/.kube/config
Kubectl 명령어로 설치 확인
kubectl get pods -A