e346a0dbd09b4fa5f755da935d69b95b3bcbc534
Kubespray
해당 문서는 kubespray를 통한 kubernetes 설치에 대한 내용을 작성한 문서입니다.
문서의 모든 기준은 Rocky OS 9 기준으로 작성 되었습니다.
마지막 갱신 날짜 : 2023년 03월 16일
0. Git 설치 & pip3 설치
- Git Install (Rocky OS 9 기준)
- RedHat 계열이면 아래와 동일
dnf install -y git
dnf install -y python3-pip
오프라인 환경일 경우
pip download -r ./kubespray/requirements.txt -d ./test/
- 오프라인 환경에서 진행을 할 경우 ansible을 사용하기 위한 패키지를 온라인 환경에서 옮겨 올 필요가 있다
- 위 커맨드를 온라인 환경에서 진행 후 ./test 디렉토리 내 모든 파일을 옮겨준다 (아래 1번 과정을 진행 후 진행)
cd /tmp/releases
- 오픈망에서 ansible-playbook을 수행할 경우 해당 디렉토리에 내려 받은 설치에 필요한 패키지들이 있다.
pip install -r requirements.txt --no-index --find-links 경로
- 온라인 환경에서 옮겨온 디렉토리의 경로를 지정하여 ansible을 위한 패키지를 설치한다
- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-udvjl15t/cryptography/ 에러가 발생할 경우
- setuptools에서 발생하는 에러
- 업그레이드를 하면 해결이 되기도 함
- pip3 install --upgrade --ignore-installed pip setuptools
1. kubespray 준비
git clone -b release-2.21 --single-branch https://github.com/kubernetes-sigs/kubespray.git
cd kubespray/
- kubespray github 에서 최신 버전의 kubespray를 내려 받는다.
- 정식으로 release 된 버전을 받아야하기 때문에 -b 옵션으로 브랜치를 지정한다.
cp -rfp inventory/sample inventory/junghun
- sample inventory를 복사하여 자신의 inventory를 생성한다.
2. Node 준비
- SSH 설정
ansible-playbook을 수행하는 node에서 cluster를 구성할 모든 node에 패스워드 입력 없이 접속이 가능하여야 한다.
ansible-playbook을 수행하는 node가 cluster를 구성하는 node일 경우 자기 자신도 포함
dnf install -y sshpass
ssh-keygen -t rsa
- SSH 등록 (root 유저)
ssh-copy-id root@IP
3. inventory 작성
cluster를 구성할 node들의 hostname과 IP를 작성한다.
해당 프로젝트에서 node.conf와 set.sh을 내려받아 node.conf에 node 정보를 입력 후 set.sh을 사용하여도 된다.
vi 혹은 nano 등 에디터를 이용한 방법
vi inventory/junghun/inventory.ini
- 아래의 예제 처럼 자신의 node 정보를 기입
[all]
node1 ansible_host=95.54.0.12 ip=10.3.0.1 #etcd_member_name=etcd1
node2 ansible_host=95.54.0.13 ip=10.3.0.1 #etcd_member_name=etcd1
#node1 ansible_port=22 ansible_host=95.54.0.12 ip=10.3.0.1 #etcd_member_name=etcd1
#만약 ssh 포트가 22가 아닐 경우 위와 같이 포트를 지정해준다.
# ## configure a bastion host if your nodes are not directly reachable
# [bastion]
[kube_control_plane]
node1
[etcd]
node1
[kube_node]
node2
[calico_rr]
[k8s_cluster:children]
kube_control_plane
kube_node
calico_rr
set.sh을 통한 inventory 작성 방법
vi node.conf
- node.conf를 vi 혹은 nano 에디터로 편집한다
chmod +x set.sh
./set.sh kubespray/inventory/junghun/
- ./set.sh 뒤의 경로는 자신의 inventory의 inventory.ini가 존재하는 경로이다.
3. parameters 값 변경
kubernetes를 구성하기 위해 생성되는 static pod 혹은 cni 등에 대한 설정
첫번째 설정
cd /root/kubespray/inventory/junghun/group_vars/all
- 본인의 inventory의 all 경로로 이동
vi all.yml
- all.yml을 vi 혹은 nano 등의 에디터로 수정
## External LB example config
## apiserver_loadbalancer_domain_name: "elb.some.domain"
# loadbalancer_apiserver:
# address: 1.2.3.4
# port: 1234
- master 다중화를 할 경우 해당 부분의 내용을 적절한 값으로 수정
## Upstream dns servers
# upstream_dns_servers:
# - 8.8.8.8
# - 8.8.4.4
- coredns의 upstream 서버 설정이 필요할 경우 해당 부분을 적절한 값으로 수정
vi offline.yml
- 해당 문서는 폐쇄망 환경 기준임으로 offline.yml을 수정
## Global Offline settings
### Private Container Image Registry
# registry_host: "myprivateregisry.com"
# files_repo: "http://myprivatehttpd"
### If using CentOS, RedHat, AlmaLinux or Fedora
# yum_repo: "http://myinternalyumrepo"
### If using Debian
# debian_repo: "http://myinternaldebianrepo"
### If using Ubuntu
# ubuntu_repo: "http://myinternalubunturepo"
## Container Registry overrides
# kube_image_repo: "{{ registry_host }}"
# gcr_image_repo: "{{ registry_host }}"
# github_image_repo: "{{ registry_host }}"
# docker_image_repo: "{{ registry_host }}"
# quay_image_repo: "{{ registry_host }}"
## Kubernetes components
# kubeadm_download_url: "{{ files_repo }}/storage.googleapis.com/kubernetes-release/release/{{ kubeadm_version }}/bin/linux/{{ image_arch }}/kubeadm"
# kubectl_download_url: "{{ files_repo }}/storage.googleapis.com/kubernetes-release/release/{{ kube_version }}/bin/linux/{{ image_arch }}/kubectl"
# kubelet_download_url: "{{ files_repo }}/storage.googleapis.com/kubernetes-release/release/{{ kube_version }}/bin/linux/{{ image_arch }}/kubelet"
## CNI Plugins
# cni_download_url: "{{ files_repo }}/github.com/containernetworking/plugins/releases/download/{{ cni_version }}/cni-plugins-linux-{{ image_arch }}-{{ cni_version }}.tgz"
## cri-tools
# crictl_download_url: "{{ files_repo }}/github.com/kubernetes-sigs/cri-tools/releases/download/{{ crictl_version }}/crictl-{{ crictl_version }}-{{ ansible_system | lower }}-{{ image_arch }}.tar.gz"
## [Optional] etcd: only if you use etcd_deployment=host
# etcd_download_url: "{{ files_repo }}/github.com/etcd-io/etcd/releases/download/{{ etcd_version }}/etcd-{{ etcd_version }}-linux-{{ image_arch }}.tar.gz"
# [Optional] Calico: If using Calico network plugin
# calicoctl_download_url: "{{ files_repo }}/github.com/projectcalico/calico/releases/download/{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}"
# calicoctl_alternate_download_url: "{{ files_repo }}/github.com/projectcalico/calicoctl/releases/download/{{ calico_ctl_version }}/calicoctl-linux-{{ image_arch }}"
# [Optional] Calico with kdd: If using Calico network plugin with kdd datastore
# calico_crds_download_url: "{{ files_repo }}/github.com/projectcalico/calico/archive/{{ calico_version }}.tar.gz"
- 해당 부분의 주석을 지우고 적절한 값으로 수정 (외부와 통신이 가능할 경우 수정X)
cd /root/kubespray/inventory/junghun/group_vars/k8s_cluster
- 해당 경로로 이동 후 addons.yml , k8s-cluster.yml , k8s-net-calico.yml 를 수정
cd /root/kubespray
ansible-playbook -i inventory/junghun/inventory.ini --become --become-user=root cluster.yml
- 본인의 inventory.ini을 지정하고 cluster.yml을 ansible-playbook을 통해 실행한다
Description
Languages
Jinja
72.5%
Shell
27.5%