본문 바로가기
[Cloud]/Kubernetes

Kubernetes 설치 방법

by journes 2019. 3. 8.

Kubernetes 설치 방법

kubernetes 학습을 위해 VirtualBox 환경에서 설치해봤던 내용을 간단하게 정리 해 봅니다.  


1.설치환경

  • VirtualBox
    • Master Node : ubuntu 16.04 LTS (1대)
    • Worker Node : ubuntu 16.04 LTS (2대)


  • Kubernetes
    • Network Addon  : flannel
    • Dashboard Addon : Dashboard


  • Kubeadm
    • Kubernetes 쉬운설치를 위해 활용
  • Docker  1.31.1
    • Kubernetes 권장 버전 설치.


  • 모든 Node에서 root User로 설치




* IP는 상황에 따라 변경하시면 됩니다.


  • 가상의 Master, Worker Node (VM) 생성.
  • Kubernetes Dashboard는 Master Node 에서 운영.
  • Virtual Box에서 “NAT 네트워크” 생성 - 10.0.0.24



2-1. Mster Node설정

  • /etc/network/interfaces를 아래와 같이 수정





2-2. Worker Node설정

  • Node1 의 /etc/network/interfaces를 아래와 같이 수정.




Node1 의 /etc/network/interfaces를 아래와 같이 수정.



3.Package설치

3-1. 모든 노드 설치

  • swapoff
    • 간단하게 스크립트 작성  

#vi /root/swapoff.sh   (퍼미션 755 변경 )

1
2
3
#!/bin/sh
 
/sbin/swapoff -a
cs



    • rc.local에 등록

#vi /etc/rc.local

1
2
#swapoff
su root -"/root/swapoff.sh &"
cs


Docker 설치

1
2
3
4
5
6
# sudo apt-get update
# sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# sudo apt-get update
# sudo apt-get install docker.io
cs


Kubernetes 설치.

1
2
3
4
5
# sudo apt-get update && apt-get install -y apt-transport-https
# sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
# sudo echo deb http://apt.kubernetes.io/ kubernetes-xenial main > /etc/apt/sources.list.d/kubernetes.list
# sudo apt-get update
# sudo apt-get install -y kubelet kubeadm
cs


3-2. Master 노드 설치

  • Kuberctl 설치

1
$ sudo snap install kubectl --classic
cs

Snap 가 없으면 #sudo apt install snapd 설치

4.Cluster구축

4-1. Master 노드 설치


  • Kuberadm 초기화(Cluster 생성)
  • Key 값 확인 (Worker Node 에서 join 시 사용)
  • 10.0.0.11은 Master Node NAT IP 임.
1
2
3
$ sudo kubeadm init --apiserver-advertise-address=192.168.20.6 --pod-network-cidr=10.244.0.0/16
...
kubeadm join --token 76f75a.6fbcc5e0e6e74c89 10.0.0.11:6443
cs


Kuberctl config 설정
1
2
3
# mkdir -p $HOME/.kube
# sudo cp -/etc/kubernetes/admin.conf $HOME/.kube/config
# sudo chown $(id -u):$(id -g) $HOME/.kube/config
cs


Network Addon (flannel) 설치

1
2
#kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
 
cs


4-2. Worker 노드 설치

  • Cluster 참여 (각 node에서 실행)
1
2
$ sudo kubeadm join --token 76f75a.6fbcc5e0e6e74c89 10.0.0.11:6443
 
cs

4-3. 확인

  • Master Node에서 Cluster 확인

1
2
3
4
5
6
#kubectl get node
NAME        STATUS    ROLES     AGE       VERSION
master182   Ready     master    1d        v1.10.0
node183     Ready     <none>    1d        v1.10.0
node184     Ready     <none>    1d        v1.10.0
 
cs

Master Node에서 Dashboard 접속

5.kubernetes-board 설치

5-1. Master Node 작업, External IP 접속 변경.


  • kubectl -n kube-system edit service kubernetes-dashboard   명령 후 config 수정
    • board의 접속을 external IP로 변경 하기 위힘.
      • Type : ClusterIP 를 Nodeport로 변경  
      • 기본 web 접속이  NAT IP (ClusterIP) 되어 있어 NodePort로 변경


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
# services "kubernetes-dashboard" was not valid:
* spec.type: Unsupported value: "Nodeport": supported values: "ClusterIP""ExternalName""LoadBalancer""NodePort"
#
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: 2018-04-12T02:03:22Z
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
  resourceVersion: "54456"
  selfLink: /api/v1/namespaces/kube-system/services/kubernetes-dashboard
  uid: ad7773ab-3df5-11e8-a739-080027327feb
spec:
  clusterIP: 10.98.83.22
  ports:
  - port: 443
    protocol: TCP
    targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
  sessionAffinity: None
  type: Nodeport            ←- type을   ClientIP 에서  Nodeport 로 변경
status:
  loadBalancer: {}
cs


5-2. 권한 추가.

  • admin 권한 추가.

1
2
root@master182:~# kubectl create clusterrolebinding add-on-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:kubernetes-dashboard
clusterrolebinding.rbac.authorization.k8s.io "add-on-cluster-admin" created
cs

5-3.  kubernetes-board 실행

  • --Address :  master-node의 External IP
  • --Port : 임의의 포트 지정.

1
2
root@master182:~# kubectl proxy --port=8001 --address="192.168.20.6" --accept-hosts="^*$" &
Starting to serve on 192.168.0.182:9999
cs