kubernetes를 설치하는 여러 방법 중에 kubespray를 이용하는 방법으로 설치를 해보겠습니다.
$ ssh-keygen -t rsa
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
2. kubespray 파일을 clone 합니다.
$ git clone https://github.com/kubernetes-sigs/kubespray.git -b v2.17.1
3. python 설치합니다.
$ sudo apt updte
$ sudo apt install -y python3-pip
4. kubespray 파이썬 패키지 install
$ cd kubespray/
$ sudo pip3 install -r requirements.txt
5. inventory 설정
$ cp -r inventory/sample inventory/mycluster
# ## 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]
node1 ansible_host=192.168.0.45 ip=192.168.0.45 etcd_member_name=etcd1
# node2 ansible_host=95.54.0.13 # ip=10.3.0.2 etcd_member_name=etcd2
# node3 ansible_host=95.54.0.14 # ip=10.3.0.3 etcd_member_name=etcd3
# node4 ansible_host=95.54.0.15 # ip=10.3.0.4 etcd_member_name=etcd4
# node5 ansible_host=95.54.0.16 # ip=10.3.0.5 etcd_member_name=etcd5
# node6 ansible_host=95.54.0.17 # ip=10.3.0.6 etcd_member_name=etcd6
# ## configure a bastion host if your nodes are not directly reachable
# [bastion]
# bastion ansible_host=x.x.x.x ansible_user=some_user
[kube_control_plane]
node1
# node2
# node3
[etcd]
node1
# node2
# node3
[kube_node]
node1
# node3
# node4
# node5
# node6
[calico_rr]
[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr
~
~
6. kubespray 설치
$ ansible-playbook -i inventory/mycluster/inventory.ini -become --become-user=root cluster.yml --extra-vars "ansible_sudo_pass=비밀번호"
7. kubernetes 설치 확인
(kubectl 바이너리는 따로 설치해야 합니다.)
$ kubectl get nodes