루나스의 기술공방
Kubernetes (Master - Slave) Deployment 본문
<개요>
Kubernetes (K8s) : 오픈소스 컨테이너 관리 시스템
플랫폼에서 (자동 Deploy, Scaleing, 여러 호스트로 이루어진 클러스터간의 Application 컨테이너 작업)
- (On-premises, Hybrid, Public Cloud)를 가리지 않고, Deployment작업을 편리하게 해준다.
- (CNCF) Cloud Native Computing Foundation에 의해서 제작시작...
- Master-Slave구조로 이루어져 있다.
- [etcd / flannel / kube-apiserver / kube-controller-manager / kube-scheduler / kubelet / kube-proxy / docker]등으로 이루어져 있음
<설치과정>
*Master 노드는 100.0.0.71, Slave 노드는 100.0.0.72이라 가정
*본 문서는 Ubuntu 16.04 LTS Server에 설치하는것을 가정
1. 패키지 업데이트
apt-get update -y #패키지 업데이트
2. 서로의 hostname설정
{{Master-Node설정}}
nano /etc/hosts #host 수정
100.0.0.71 master-node #host파일에 각각 노드 host 추가
100.0.0.72 slave-node
hostnamectl set-hostname master-node #마스터 노드 호스트명 변경
{{Slave-Node설정}}
nano /etc/hosts #host 수정
100.0.0.71 master-node #host파일에 각각 노드 host 추가
100.0.0.72 slave-node
hostnamectl set-hostname slave-node #슬레이브 노드 호스트명 변경
3. Swap 비활성화
*kubelets가 swap메모리를 지원하지 않기에, /etc/fstab에서 swap이 존재시, 정지되기 때문
swapoff -a #시스템상 Swap 비활성화
nano /etc/fstab #fstab(File-System Table) 파일 수정
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda4 during installation
UUID=6f612675-026a-4d52-9d02-547030ff8a7e / ext4 errors=remount-ro 0 1
# swap was on /dev/sda6 during installation
#UUID=46ee415b-4afa-4134-9821-c4e4c275e264 none swap sw 0 0 #앞에 '#'을 붙힘으로, Swap을 영구정지
/dev/sda5 /Data ext4 defaults 0 0
4. Docker설치
apt-get install apt-transport-https ca-certificates curl software-properties-common -y #필요 패키지 설치
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - #도커 GPG키 삽입
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" #도커 Repository설치
apt-get update -y #패키지 업데이트
apt-get install docker-ce -y #도커 설치
5. Kubernetes설치
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - #쿠버네츠 GPG키 삽입
echo 'deb http://apt.kubernetes.io/ kubernetes-xenial main' | sudo tee /etc/apt/sources.list.d/kubernetes.list #쿠버네츠 repository추가
apt-get update -y #패키지 업데이트
apt-get install kubelet kubeadm kubectl -y #kubelet, kubeadm, kubectl 설치
6. Master Node 설정
kubeadm init --pod-network-cidr=100.0.0.0/16 --apiserver-advertise-address=100.0.0.71 #클러스터 시작
Your Kubernetes master has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node
as root:
kubeadm join --token 62b281.f819128770e900a3 100.0.0.71:6443 --discovery-token-ca-cert-hash sha256:68ce767b188860676e6952fdeddd4e9fd45ab141a3d6d50c02505fa0d4d44686
#'Token'과 'Hash값' 적어둘것
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config #kubectl 사용가능하기 위하여, 일반 사용자로 명령어 실행
kubectl get nodes #실행중인 노드 확인
NAME STATUS ROLES AGE VERSION
master-node NotReady master 14m v1.9.4
7. Slave Node설정
kubeadm join --token 62b281.f819128770e900a3 100.0.0.71:6443 --discovery-token-ca-cert-hash sha256:68ce767b188860676e6952fdeddd4e9fd45ab141a3d6d50c02505fa0d4d44686 #Master-Node에 연결
[discovery] Trying to connect to API Server "100.0.0.71:6443"
[discovery] Created cluster-info discovery client, requesting info from "https://100.0.0.71:6443"
[discovery] Requesting info from "https://100.0.0.71:6443" again to validate TLS against the pinned public key
[discovery] Cluster info signature and contents are valid and TLS certificate validates against pinned roots, will use API Server "100.0.0.71:6443"
[discovery] Successfully established connection with API Server "100.0.0.71:6443"
This node has joined the cluster:
* Certificate signing request was sent to master and a response
was received.
* The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the master to see this node join the cluster.
*kubeadm reset : [sudo 권한상승 필요] kubelet 클러스터의 삭제
[출처] : alibaba-cloud.medium.com/how-to-install-and-deploy-kubernetes-on-ubuntu-16-04-6769fd1646db