[k8s] kubespray 를 사용한 bare-metal 서버에 쿠버네티스 설치하기
kubespray를 사용하여 VM에 Kubernetes 설치하는 방법을 다룬다.
테스트 환경의 VM은 CentOS 2대이며, master 1대, worker node 1대로 구성한다.
1. 설치용 서버 사전 설정
kubespray를 실행할 mater 에 관련 hosts 정보 추가
xxxxxxxxxx
#tail /etc/hosts
1.1.1.16 k8s-master
1.1.1.35 k8s-worker
ssh key 생성
xxxxxxxxxx
[root@k8s-master ~]# ssh-keygen -t rsa
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:TsrGlaHo3jqUBEiORQIZnBqyVO1xU2UKIEBN+prE0Dc root@k8s-master
The key's randomart image is:
+---[RSA 2048]----+
|*B=+.. ....o |
|B=* .o.o. o |
|** o. o E. |
|+.. .o . o |
| E... S |
| .o.Eo = |
|.E..E = . |
|+ o.+ |
|.. oo. |
+----[SHA256]-----+
ssh key 배포
x
#ssh-copy-id root@k8s-master
#ssh-copy-id root@k8s-worker
kubespray에서 사용하는 관련 package 설치
- kubespray는 ansible 기반으로 설치되기 때문에 ansible 과 관련된 package 설치가 필요하다.
x
[root@k8s-master ~] yum install https://centos7.iuscommunity.org/ius-release.rpm -y
[root@k8s-master ~] yum install python36u python36u-pip wget -y
[root@k8s-master ~] pip3.6 install ansible netaddr jinja2
kubespray 다운로드
x
[root@k8s-master ~] git clone https://github.com/kubernetes-sigs/kubespray
[root@k8s-master ~] cd kubespray
[root@k8s-master ~] pip3.6 install -r requirements.txt
2. OS 사전 설정
Master, Worker 를 포함한 모든 노드에서 실행한다.
Swap OFF : 스와핑에 의한 성능 저하를 예방하기 위해 swap 영역을 제거한다.
xxxxxxxxxx
[root@k8s-master ~]# swapoff -a
xxxxxxxxxx
[root@k8s-worker ~]# swapoff -a
SeLinux 해제 : 대부분의 패키지 설치에서 사전 작업 1순위인 .. Selinux 를 disable 한다.
xxxxxxxxxx
[root@k8s-master ~]# setenforce 0
setenforce: SELinux is disabled
xxxxxxxxxx
[root@k8s-worker ~]# setenforce 0
setenforce: SELinux is disabled
3. Ansible playbook 실행하여 설치
Ansible Inventory 설정
- Sample 을 복사하여 설치 환경에 맞게 수정한다.
xxxxxxxxxx
[root@k8s-master sample]# cp ~/kubespray/inventory/sample/inventory.ini ~/kubespray/inventory/inventory.ini
[root@k8s-master kubespray]# cat ~/kubespray/inventory/inventory.ini
[all]
k8s-master ansible_ssh_host=1.1.1.16 ip=1.1.1.16
k8s-worker ansible_ssh_host=1.1.1.35 ip=1.1.1.35
[kube-master]
k8s-master
[etcd]
k8s-master
[kube-node]
k8s-worker
[k8s-cluster:children]
kube-master
kube-node
ansible playbook 실행으로 kubernetes 설치
xxxxxxxxxx
[root@k8s-master kubespray]# ansible-playbook --flush-cache -u root -b -i ~/kubespray/inventory/inventory.ini ~/kubespray/cluster.yml
...
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
k8s-master : ok=650 changed=128 unreachable=0 failed=0
localhost : ok=1 changed=0 unreachable=0 failed=0
4. kubectl 로 설치 확인
kubectl 설치
CentOS 기준으로 아래 명령어를 실행한다.
xxxxxxxxxx
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
yum install -y kubectl
kubectl get ndoes
명령어로 Cluster 노드 확인xxxxxxxxxx
[root@k8s-master kubespray]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 20m v1.15.3
k8s-worker Ready <none> 6m25s v1.15.3
'k8s' 카테고리의 다른 글
[k8s] node.js 애플리케이션 쿠버네티스(kubernetes) 클러스터에 디플로이먼트(deployment)로 배포하기 (1) | 2019.10.11 |
---|---|
[k8s] kubespray로 쿠버네티스 설치 후 calico-node 에서 CrashLoopBackOff 에러가 날 경우 (0) | 2019.09.06 |
[K8S] Azure AKS 클러스터에서 helm 차트 사용하기 (0) | 2019.08.26 |
[K8S] Azure CLI 로 AKS 클러스터 구성 및 로컬 환경에서 kubectl 로 AKS 클러스터 연결하기 (0) | 2019.08.23 |
[k8s] 공개용 Docker Image를 다운로드하여 사설 Registry 로 옮기기 (0) | 2019.07.19 |