Kubernetes 설치

서버|2017. 1. 12. 16:19


Ubuntu 14.04 LTS, Kubernetes 1.5.1 버전을 기준으로 작성한다.

Kubernetes 설치를 위한 호스트 정보는 다음과 같다.

 master

 192.168.50.11

 node(minion)

 192.168.50.2

 node(minion)

 192.168.50.11



1.

root로 로그인


2.

모든 호스트에 docker 설치

http://lng1982.tistory.com/268


3.

kubernetes pods 내부의 컨테이너 관리를 위해 설치

# apt-get install bridge-utils


4.

git 설치 및 kubernetes clone

master 노드에만 설치한다.

# apt-get install git -y

# git clone https://github.com/kubernetes/kubernetes.git


5.

설치 파일 및 바이너리 다운로드

# cd /root/kubernetes/cluster/ubuntu

# ./download-release.sh

Prepare flannel 0.5.5 release ...

Prepare etcd 2.3.1 release ...

Prepare kubernetes 1.4.7 release ...

Done! All your binaries locate in kubernetes/cluster/ubuntu/binaries directory


6.

쿠버네티스 node 설정

# vi /root/kubernetes/cluster/ubuntu/config-default.sh

아래 설정에 대해서만 수정하도록 한다. 

nodes에 추가되는 아이피는 마스터 서버를 첫 번째로 지정하고 노드 서버들은 그 뒤에 나열하면 된다. (스페이스로 구분)

roles에 추가되어 있는 a는 마스터를 의미하여 i는 노드를 ai는 마스터&노드를 의미한다. nodes 설정에 추가된 호스트 리스트 갯수에 맞게 설정한다.

export nodes=${nodes:-"root@192.168.50.11 root@192.168.50.2"}

roles=${roles:-"ai i"}

export NUM_NODES=2


7.

RSA 키 생성

# ssh-keygen -t rsa

계정의 홈 디렉토리 하위의 .ssh 폴더로 이동 후 아래 명령어 실행

# cat id_rsa.pub >> authorized_keys


8.

클러스터 배포 및 구동

kube-up 스크립트가 실행되면 바이너리, 설정 파일이 모든 node 머신에 복사되고(using scp) kubernetes 가 실행된다.

# cd /root/kubernetes/cluster

# KUBERNETES_PROVIDER=ubuntu ./kube-up.sh

... Starting cluster using provider: ubuntu

... calling verify-prereqs

Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

... calling kube-up

~/kubernetes/cluster/ubuntu ~/kubernetes/cluster

Prepare flannel 0.5.5 release ...

Prepare etcd 2.3.1 release ...

Prepare kubernetes 1.5.1 release ...

Done! All your binaries locate in kubernetes/cluster/ubuntu/binaries directory

~/kubernetes/cluster


Deploying master and node on machine 192.168.50.11 <- master, minion 설치 및 실행

make-ca-cert.sh                                                                       100% 4136     4.0KB/s   00:00

easy-rsa.tar.gz                                                                         100%   42KB  42.4KB/s   00:00

config-default.sh                                                                      100% 6250     6.1KB/s   00:00

util.sh                                                                                    100%   29KB  29.1KB/s   00:00

kube-proxy.conf                                                                       100%  688     0.7KB/s   00:00

kubelet.conf                                                                            100%  645     0.6KB/s   00:00

kubelet                                                                                  100% 2158     2.1KB/s   00:00

kube-proxy                                                                             100% 2233     2.2KB/s   00:00

etcd.conf                                                                                100%  707     0.7KB/s   00:00

kube-scheduler.conf                                                                  100%  682     0.7KB/s   00:00

kube-apiserver.conf                                                                   100%  682     0.7KB/s   00:00

kube-controller-manager.conf                                                      100%  761     0.7KB/s   00:00

kube-controller-manager                                                            100% 2672     2.6KB/s   00:00

etcd                                                                                       100% 2073     2.0KB/s   00:00

kube-scheduler                                                                         100% 2360     2.3KB/s   00:00

kube-apiserver                                                                          100% 2358     2.3KB/s   00:00

reconfDocker.sh                                                                        100% 2183     2.1KB/s   00:00

kube-controller-manager                                                             100%   97MB  48.3MB/s   00:02

flanneld                                                                                   100%   16MB  15.8MB/s   00:00

etcd                                                                                        100%   16MB  15.9MB/s   00:00

etcdctl                                                                                     100%   14MB  13.7MB/s   00:00

kube-scheduler                                                                          100%   50MB  50.4MB/s   00:01

kube-apiserver                                                                           100%  117MB  39.1MB/s   00:03

flanneld                                                                                    100%   16MB  15.8MB/s   00:00

kubelet                                                                                    100%  103MB  25.7MB/s   00:04

kube-proxy                                                                               100%   44MB  43.6MB/s   00:01

flanneld.conf                                                                             100%  579     0.6KB/s   00:00

flanneld                                                                                   100% 2121     2.1KB/s   00:00

flanneld.conf                                                                             100%  570     0.6KB/s   00:00

flanneld                                                                                   100% 2131     2.1KB/s   00:00

etcd start/running, process 32528

{"Network":"172.16.0.0/16", "Backend": {"Type": "vxlan"}}

docker stop/waiting

docker start/running, process 32711

Connection to 192.168.50.11 closed.


Deploying node on machine 192.168.50.2 <- minion 설치 및 실행

config-default.sh                                                                     100% 6250     6.1KB/s   00:00

util.sh                                                                                    100%   29KB  29.1KB/s   00:00

reconfDocker.sh                                                                       100% 2183     2.1KB/s   00:00

kube-proxy.conf                                                                       100%  688     0.7KB/s   00:00

kubelet.conf                                                                            100%  645     0.6KB/s   00:00

kubelet                                                                                  100% 2158     2.1KB/s   00:00

kube-proxy                                                                             100% 2233     2.2KB/s   00:00

flanneld                                                                                 100%   16MB  15.8MB/s   00:01

kubelet                                                                                  100%  103MB  25.7MB/s   00:04

kube-proxy                                                                             100%   44MB  43.6MB/s   00:01

flanneld.conf                                                                           100%  579     0.6KB/s   00:00

flanneld                                                                                 100% 2121     2.1KB/s   00:00

flanneld start/running, process 13415

docker stop/waiting

docker start/running, process 13556

Connection to 192.168.50.2 closed.

Validating master

Validating root@192.168.50.11

Validating root@192.168.50.2

Using master 192.168.50.11

Cluster "ubuntu" set.

User "ubuntu" set.

Context "ubuntu" set.

Switched to context "ubuntu".

Wrote config for ubuntu to /root/.kube/config

... calling validate-cluster

Found 2 node(s).

NAME            STATUS    AGE

192.168.50.11   Ready     2h

192.168.50.2    Ready     1d

Validate output:

NAME                 STATUS    MESSAGE              ERROR

controller-manager   Healthy   ok

scheduler            Healthy   ok

etcd-0               Healthy   {"health": "true"}

Cluster validation succeeded

Done, listing cluster services:


Kubernetes master is running at http://192.168.50.11:8080


To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.


8.

패스 추가

root 홈 디렉토리의 .bashrc 파일에 아래 패스 추가

PATH=$PATH:/root/kubernetes/cluster/ubuntu/binaries/

PATH=$PATH:/opt/bin/


9.

노드 확인

# kubectl get nodes

NAME            STATUS    AGE

192.168.50.11   Ready     4h

192.168.50.2    Ready     1d



[명령어 모음]

>> 노드 리스트

kubectl get nodes


>> pod 생성

kubectl run my-nginx --image=nginx --replicas=2 --port=80


>> public internet에 서비스 공개

kubectl expose deployment my-nginx --target-port=80 --type=LoadBalancer


>> 팟 구성 및 상태

kubectl get pods

kubectl get pods --all-namespaces


>> pod의 서비스 상태

kubectl get service

kubectl describe service


>> 배포 상태 확인

kubectl get deployment


>> 컨테이너 삭제 public ip 삭제

kubectl delete deployment,service my-nginx


>> 라벨 확인

kubectl get pods -L run


>> pod 죽이기

kubectl delete pod <POT NAME>


>> pod 업데이트 하기 (하나 하나씩 진행)

kubectl set image deployment/my-nginx my-nginx=nginx:1.9.1


>> 롤백

kubectl rollout history deployment/my-nginx

kubectl rollout undo deployment/my-nginx --to-revision=1



kubectl get : list resources

kubectl describe : show detailed information about a resource

kubectl logs : print the logs from a container in a pod

kubectl exec : execute a command on a container in a pod





댓글()