반응형

현재 AWS  EC2 에 올라가 있는 ubuntu 에 kubernetes를 설치해 보았다. 

그런데 설치를 하다보니 프리티어로 받은 t2.micro 가지고는 너무 성능이 느렸다. 거의 접속도 못할 지경에 이르렀다. 그래서 어차피 설치하고 지울거니깐 t2.large로 올렸다.


설치 전에 Docker 가 먼저 설치 되어 있어야 한다.

(Docker 가 설치 안되어 있다면 https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository 여기 참고하거나 아래 링크 에도 내용은 나와있다.)


https://kubernetes.io/docs/setup/independent/install-kubeadm/


여기에 들어가보면 친절하게 설치 하는 방법을 찾을 수 있다.

내용을 살펴보면 Docker 설치도 포함하고 있어서 Docker 가 설치되어 있지 않다면 그대로 따라 하면 된다.


그리고 나는 Ubuntu 에 설치를 하니 아래와 같이 명령어를 실행 했다. 혹시 명령어 실행중 permission 에러가 나면 sudo 붙이고 실행 하면 된다.

apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb http://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl

이렇게 하면 kubelet, kubeadm, kubectl 이 설치가 된다.


https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/


그 다음 스텝으로 위 링크로 들어가서 클러스터를 생성 하면 된다.


여기 나와 있는 내용중에 보면 사양이 나와있다. 

  • One or more machines running a deb/rpm-compatible OS, for example Ubuntu or CentOS
  • 2 GB or more of RAM per machine. Any less leaves little room for your apps.
  • 2 CPUs or more on the master
  • Full network connectivity among all machines in the cluster. A public or private network is fine.

최소 사양이다. 이러니 t2.micro 로는 역부족이었다.

kubeadm init <args> 

이렇게 명령어를 날리면 뭔가 내용이 올라오면서 설치가 된다. args는 다양하게 있으나 나는 우선 필요가 없어서 안 넣었다. 설치가 완료되면 아래와 같은 내용들이 나온다. (ip랑 port, 토큰 부분은 ㅌㅌㅌ로 처리했다.)


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 <ip>:<port> --token ㅌㅌㅌㅌㅌㅌㅌㅌ --discovery-token-ca-cert-hash sha256:ㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌㅌ


잘 읽어보면 cluster 시작하려면 .kube에 config 파일을 만들라는 내용이 있다. 아주 편리하게 저 내용을 그대로 복사해서 붙여넣으면 된다. 그리고 아래 join에 나오는 내용은 잘 복사해서 저장해두자.


이렇게 하고 "kubectl get pods --all-namespaces" 라고 치면 아래와 비슷하게 나온다. 


NAMESPACE     NAME                                       READY     STATUS    RESTARTS   AGE

kube-system   coredns-78fcdf6894-86s7n                   0/1       Pending   0          7m

kube-system   coredns-78fcdf6894-ngk7x                   0/1       Pending   0          7m

kube-system   etcd-ip-172-31-22-134                      1/1       Running   0          7m

kube-system   kube-apiserver-ip-172-31-22-134            1/1       Running   0          7m

kube-system   kube-controller-manager-ip-172-31-22-134   1/1       Running   0          6m

kube-system   kube-proxy-46x54                           1/1       Running   0          7m

kube-system   kube-scheduler-ip-172-31-22-134            1/1       Running   0          6m


그리고 위에도 써있듯이 cluster에 network를 배포해야 한다. 

위 링크(https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#pod-network 또는 https://kubernetes.io/docs/concepts/cluster-administration/addons/) 따라가보면 종류별로 방법이 있다. 설치하고 나서 다음과 같이 확인 해보면 된다.


 kubectl get nodes

NAME               STATUS    ROLES     AGE       VERSION

ip-111-11-11-111   Ready     master    32m       v1.11.2


아직 node 를 추가 못해봤는데 다음에는 node 도 따로 추가해봐야겠다.


728x90
반응형

+ Recent posts