Kubernetes를 쌩으로(?) 설치하기 너무 귀찮기에

조금 편하게 설치하기 위해 Kubespray를 이용해보기로 했다.

 

   - kubernetes.io/ko/docs/setup/production-environment/tools/kubespray/

 

Kubespray로 쿠버네티스 설치하기

이 가이드는 Kubespray를 이용하여 GCE, Azure, OpenStack, AWS, vSphere, Packet(베어메탈), Oracle Cloud infrastructure(실험적) 또는 베어메탈 등에서 운영되는 쿠버네티스 클러스터를 설치하는 과정을 보여준다. Kub

kubernetes.io

설치를 진행한 환경은 다음과 같다.

 

  - Location : Home (SKB Internet - 500Mbps)

  - Host OS : Windows 10 64bit

  - VM S/W : VirtualBox

  - Guest OS : Ubuntu 20.04 Server 64bit (3개 VM)

    . CPU : 2 Core

    . Mem : 4096 MB

    . N/W : Bridge

 

 

1. python 설치

  - 설치되어 있는 python을 확인해보자.

 

$ ls /usr/bin | grep python
python3
python3.8

 

  - ubuntu 20.04 에서는 기본적으로 3.8이 설치되어 있는듯하다.

  - 사용하기 편하도록 기본 `python`에 mapping 하자.

 

$ sudo update-alternatives --config python
update-alternatives: error: no alternatives for python

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
$ sudo update-alternatives --config python

$ python --version
Python 3.8.5

 

  - `pip`도 설치해보자.

 

$ sudo apt install python3-pip

$ sudo update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1
$ sudo update-alternatives --config pip3

$ pip --version
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)


2. ansible 설치

  - kubespray는 `ansible`을 기본으로 사용한다.

 

$ sudo apt install ansible python3-argcomplete

$ ansible --version
ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/whatwant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0]

 

3. SSH 키 복사하기

  - `ansible`을 기본으로 사용하기에, 3대의 VM에 ssh 접속을 바로 할 수 있도록 SSH 키를 모두 복사해야 한다.

 

  - `master`로 사용할 VM에서 `ssh-keygen`으로 key를 생성한 뒤, copy하면 된다.

  - 개인적으로 사용하는 SSH 키가 있다면 그것을 사용하면 되고...

 

$ ssh-keygen

$ ssh-copy-id 192.168.122.10
(Master Node와 Worker Node에 모두 키를 복사)

 

 

4. swap 메모리 비활성화

  - kubernetes를 설치하기 위해선 swap 메모리를 모두 비활성화 해야 한다.

  - master/worker node에 사용할 3대의 VM 모두 꺼버리자!

 

$ sudo swapoff -a

 

 

5. ip forward 설정

  - K8s는 가상 네트워크 환경을 사용해야 하기에 ip_forward를 활성화 해야 한다.

  - master/worker node에 사용할 3대의 VM 모두 적용 !!!

 

$ sudo sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'

$ cat /proc/sys/net/ipv4/ip_forward
1

 

  - 위와 같은 설정은 본래 재부팅하면 풀려야 하는데... 재부팅해도 그대로 유지되기에 내버려두고 있다.
  - 나중에 한 번 확인해봐야 할 것 같다.

 

 

6. hosts 등록

  - hostname으로 서버에 접속할 수 있도록 hosts 파일에 3개 VM hostname을 등록하자.

  - master/worker node에 사용할 3대의 VM 모두 적용 !!!

 

$ sudo nano /etc/hosts
192.168.100.111 master-stg
192.168.100.112 worker1
192.168.100.113 worker2

 

  - 각자의 hostname 과 IP 상황에 맞게 적용하면 된다.

 

 

7. kubespray 실행

  - `git clone` 받은 뒤, 필요한 패키지 설치하도록 하고, 나만의 환경 설정을 하자.

 

$ git clone https://github.com/kubernetes-sigs/kubespray.git

$ cd kubespray

$ git checkout release-2.15

$ sudo pip install -r requirements.txt

$ cp -rfp inventory/sample inventory/mycluster

$ declare -a IPS=(192.168.100.111 192.168.100.112 192.168.100.113)

$ CONFIG_FILE=inventory/mycluster/hosts.yaml python3 contrib/inventory_builder/inventory.py ${IPS[@]}

 

  - `cp`를 하는 것은, sample을 기본으로 나만의 inventory를 만들기 위함이다.

  - `declare`는 설치할 VM들의 IP를 적어주면 된다.

  - `CONFIG_FILE`을 실행하면 `declare`로 알려준 VM 정보들을 이용하여 config file을 만들어준다.

 

  - master node로 사용할 아이와 worker node를 사용할 아이들에 대해서 설정을 맞춰주자.

  - hostname도 맞춰서 적어주는 것이 좋다.

 

$ nano inventory/mycluster/hosts.yaml

all:
  hosts:
    master-stg:
      ansible_host: 192.168.100.111
      ip: 192.168.100.111
      access_ip: 192.168.100.111
    worker1:
      ansible_host: 192.168.100.112
      ip: 192.168.100.112
      access_ip: 192.168.100.112
    worker2:
      ansible_host: 192.168.100.113
      ip: 192.168.100.113
      access_ip: 192.168.100.113
  children:
    kube_control_plane:
      hosts:
        master-stg:
    kube_node:
      hosts:
        worker1:
        worker2:
    etcd:
      hosts:
        master-stg:
    k8s_cluster:
      children:
        kube_control_plane:
        kube_node:
    calico_rr:
      hosts: {}

 

  - addon도 필요한 것들을 true로 만들어주자.

 

$ nano ./inventory/mycluster/group_vars/k8s_cluster/addons.yml

dashboard_enabled: true
metrics_server_enabled: true
ingress_nginx_enabled: true

 

 

8. Static IP 설정

  - DHCP 설정으로 되어있으면 Node의 `/etc/resolv.conf`에 잡스러운(?) 내용이 들어가고

  - 그렇게 되면 K8s의 coredns에서 Node의 `/etc/resolv.conf`를 참고하게 되면서

  - Pod의 Container 안에 있는 `/etc/resolv.conf`에도 그 내용이 반영되어서

  - FQDN 관련해서 원하지 않는 결과가 나올 수 있다.

 

❯ cd /etc/netplan/

❯ sudo cp ./00-installer-config.yaml ./00-installer-config.yaml.210504

❯ sudo nano ./00-installer-config.yaml

network:
  ethernets:
    enp0s3:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.100.111/24]
      gateway4: 192.168.100.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
  version: 2

 

 

 

 

9. 설치

  - 이제 준비는 끝났다. 고! 고!

 

$ ansible-playbook -i inventory/mycluster/hosts.yaml  --become --become-user=root cluster.yml

 

 

10. 사용자 계정 설정

  - root 계정이 아닌 사용자 계정에서 `kubectl` 명령어를 사용하기 위해서는 다음과 같이...

 

$ mkdir -p $HOME/.kube

$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

 

11. zsh 자동 완성 셋팅

 

 

> echo "source <(kubectl completion zsh)" >> ~/.zshrc
> source ~/.zshrc

 

 

 

12. 재부팅 후

  - 희한하게 서버들을 재부팅 하고, `kubectl` 사용을 하면 API Server 연결을 거부당했다는 메시지가 나온다.

  - 그러면 swap 메모리 설정을 한 번 해주면 해결이 된다.

 

$ sudo swapoff -a

 

 

13. 결과

  - 이렇게 잘 나온다~

 

$ kubectl get nodes -o wide
NAME         STATUS   ROLES                  AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
master-stg   Ready    control-plane,master   37h   v1.20.6   192.168.100.111   <none>        Ubuntu 20.04.2 LTS   5.4.0-72-generic   docker://19.3.15
worker1      Ready    <none>                 37h   v1.20.6   192.168.100.112   <none>        Ubuntu 20.04.2 LTS   5.4.0-72-generic   docker://19.3.15
worker2      Ready    <none>                 37h   v1.20.6   192.168.100.113   <none>        Ubuntu 20.04.2 LTS   5.4.0-72-generic   docker://19.3.15

 

반응형



최근 주력으로 공부하고 있는 것은 Kubernetes와 Machine-Learning이다.

특히 현재 업무와도 관련이 있어서 더 깊이 보고 있는 것이 바로 Kubernetes인데, 이와 관련된 새로운 책 하나를 살펴보게 되었다.



취향 저격!


요즘 IT 서적들은 표지도 너무 잘 만들고, 타이포그라피도 너무 잘 하는 것 같다.

그리고, 왠지 모르게 레벨업 욕구를 불러일으키게 "15단계"라니...




희한하게 요즘 보는 책들의 지은이가 계속 일본인이네...

지은이가 IBM 클라우드 소속이라서, 책에서도 IBM 클라우드를 소개했구나 ... ^^



15단계로 구성되었다고 하지만,

1장은 단계에 속하지 않은 사전 학습 내용으로 되어있다.



2장부터 1단계 시작이다.



그런데, 살펴보면 다른 책에서는 잘 보지 못하는 재미있는 항목이 보인다.



각 Step의 뒷 부분을 보면, "참고 자료"를 하나의 섹션으로 넣어 놓았다.


실제 내용을 보면 아래와 같이 되어있다.



추가적으로 공부를 더 해보고 싶은 경우, 이 내용을 참조하면 많은 도움이 될 것 같다.



책 내용은 깔끔하다.

다만, Why 에 대한 설명을 해주는 책은 아니고, How 위주로 설명을 해주는 책으로 보인다.




설명도 잘 되어 있고, 실행 예도 잘 보여주고 있다.


다만, 15단계에 따라 하나씩 직접 해보면서 어떤 명령어들을 사용하는지 배우기에는 적합하지만,

왜 이런 구성을 가지고 있는지 등에 대해서 파악하려면 다른 책을 보는 것이 나을 것 같다.


직접 몸으로 부딪히면서 배우는 것을 좋아하시는 분들에게 추천할 수 있는 책이다.




※ 제이펍 서평단 활동을 위해 지급 받은 도서에 대한 리뷰입니다.

반응형

 

 

Kubernetes 설치를 해보자 한다.

 

 

Master Node & Worker Node 각 1대씩 구성을 하고자 한다.

 

물리적으로 분리된 BareMetal 구성을 하려고 했지만,

자유로운 설정을 통해 학습해보기 위해서 VirtualBox로 우선 진행해 보았다.

 

 

정말 훌륭한 레퍼런스는 아래 링크와 같다 !!!

  - https://medium.com/finda-tech/overview-8d169b2a54ff

 

 

 

 

1. Master & Worker Node H/W

 

  - Prerequisite

 

구분  CPU Memory Storage 
 Master 2 core 3 GB 30 GB
 Worker 2 core 2 GB 30 GB

 

  - VirtualBox

 

구분  CPU Memory Storage 
 Master 2 core 4 GB 50 GB
 Worker 2 core 4 GB 50 GB

 

    . 네트워크는 NAT가 아니라 Bridge로 잡아줬다. (공유기 환경)

 

 

 

 

 

2. Master & Worker Node S/W

 

  - Ubuntu 20.04 LTS Server 설치를 하면서, 기본적인 환경 설치는 아래 링크와 동일하게 구성하였다.

    . https://www.whatwant.com/entry/notebook-ubuntu-server

 

  - Docker 까지는 미리 설치해두었다. 설치 방법은 아래 링크와 같이 진행하였다.

    . https://www.whatwant.com/entry/Docker-Install-Ubuntu-Server-2004

 

    . kubernetes validated versions이 따로 있으니 이것에 맞추는 것을 추천한다.

 

 

 

 

3. Swap off

 

  - kubelet에서 swap을 지원하지 않기 때문에, Master/Worker 모두 swap 기능을 꺼야 한다.

 

$ sudo swapoff -a

 

  - 영구적으로 기능을 끄기 위해서는 추가 작업도 해줘야 한다.

 

$ sudo nano /etc/fstab

 

  - swap 부분을 찾아서 주석 처리 해주면 된다.

 

#/swap.img  none    swap    sw  0   0

 

 

 

 

4. cgroup driver 설정

 

  - 이미 설치된 docker에 대해서 cgroup driver를 변경해줘야 한다.

 

$ docker info

 

 

  - 지금은 "cgroupfs"로 설정되어 있는 것을 볼 수 있다. "systemd"로 변경해보자.

 

$ sudo nano /etc/docker/daemon.json

 

{

    "exec-opts": ["native.cgroupdriver=systemd"],

    "log-driver": "json-file",

    "log-opts": {

        "max-size": "100m"

    },

    "storage-driver": "overlay2"

}

 

$ sudo mkdir -p /etc/systemd/system/docker.service.d

 

$ sudo systemctl daemon-reload

 

$ sudo systemctl restart docker

 

 

  - "cgroup driver"가 잘 변경된 것을 볼 수 있다.

 

 

 

 

5. Kubernetes 기본 패키지 설치

 

  - Master/Worker Node 모두 [ kubeadm, kubelet, kubectl ] 3개의 패키지가 설치되어야 한다.

    . 부수적으로 [ kubernetes-cni, cri-tools ] 2개 패키지도 필요하다.

 

  - 아래에서 최신 버전의 주소(파일명) 확인 (16.04 이후 버전 모두 동일)

    . https://packages.cloud.google.com/apt/dists/kubernetes-xenial/main/binary-amd64/Packages

 

$ wget https://packages.cloud.google.com/apt/pool/cri-tools_1.13.0-01_amd64_4ff4588f5589826775f4a3bebd95aec5b9fb591ba8fb89a62845ffa8efe8cf22.deb

 

$ wget https://packages.cloud.google.com/apt/pool/kubeadm_1.20.1-00_amd64_7cd8d4021bb251862b755ed9c240091a532b89e6c796d58c3fdea7c9a72b878f.deb

 

$ wget https://packages.cloud.google.com/apt/pool/kubectl_1.20.1-00_amd64_b927311062e6a4610d9ac3bc8560457ab23fbd697a3052c394a1d7cc9e46a17d.deb

 

$ wget https://packages.cloud.google.com/apt/pool/kubelet_1.20.1-00_amd64_560a52294b8b339e0ca8ddbc480218e93ebb01daef0446887803815bcd0c41eb.deb

 

$ wget https://packages.cloud.google.com/apt/pool/kubernetes-cni_0.8.7-00_amd64_ca2303ea0eecadf379c65bad855f9ad7c95c16502c0e7b3d50edcb53403c500f.deb

 

  - 설치도 진행하자

 

$ sudo apt-get install socat conntrack ebtables

 

$ sudo dpkg --install ./kubernetes-cni_0.8.7-00_amd64_ca2303ea0eecadf379c65bad855f9ad7c95c16502c0e7b3d50edcb53403c500f.deb

 

$ sudo dpkg --install ./kubelet_1.20.1-00_amd64_560a52294b8b339e0ca8ddbc480218e93ebb01daef0446887803815bcd0c41eb.deb

 

$ sudo dpkg --install ./cri-tools_1.13.0-01_amd64_4ff4588f5589826775f4a3bebd95aec5b9fb591ba8fb89a62845ffa8efe8cf22.deb

 

$ sudo dpkg --install ./kubectl_1.20.1-00_amd64_b927311062e6a4610d9ac3bc8560457ab23fbd697a3052c394a1d7cc9e46a17d.deb

 

$ sudo dpkg --install ./kubeadm_1.20.1-00_amd64_7cd8d4021bb251862b755ed9c240091a532b89e6c796d58c3fdea7c9a72b878f.deb

 

 

 

 

6. Master Node 셋업

 

  - kubeadm을 이용하여 Master Node 셋업을 진행하자.

 

  - Master Node의 IP를 확인하자

 

$ ifconfig

 

  - 이제 셋업 시작~!! (뒤의 IP는 방금 확인한 IP로 교체!!)

 

$ sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.100.119

 

❯ sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.100.119

[init] Using Kubernetes version: v1.20.1

[preflight] Running pre-flight checks

[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03

[preflight] Pulling images required for setting up a Kubernetes cluster

[preflight] This might take a minute or two, depending on the speed of your internet connection

[preflight] You can also perform this action in beforehand using 'kubeadm config images pull'

[certs] Using certificateDir folder "/etc/kubernetes/pki"

[certs] Generating "ca" certificate and key

[certs] Generating "apiserver" certificate and key

[certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local master-stg] and IPs [10.96.0.1 192.168.100.119]

[certs] Generating "apiserver-kubelet-client" certificate and key

[certs] Generating "front-proxy-ca" certificate and key

[certs] Generating "front-proxy-client" certificate and key

[certs] Generating "etcd/ca" certificate and key

[certs] Generating "etcd/server" certificate and key

[certs] etcd/server serving cert is signed for DNS names [localhost master-stg] and IPs [192.168.100.119 127.0.0.1 ::1]

[certs] Generating "etcd/peer" certificate and key

[certs] etcd/peer serving cert is signed for DNS names [localhost master-stg] and IPs [192.168.100.119 127.0.0.1 ::1]

[certs] Generating "etcd/healthcheck-client" certificate and key

[certs] Generating "apiserver-etcd-client" certificate and key

[certs] Generating "sa" key and public key

[kubeconfig] Using kubeconfig folder "/etc/kubernetes"

[kubeconfig] Writing "admin.conf" kubeconfig file

[kubeconfig] Writing "kubelet.conf" kubeconfig file

[kubeconfig] Writing "controller-manager.conf" kubeconfig file

[kubeconfig] Writing "scheduler.conf" kubeconfig file

[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"

[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"

[kubelet-start] Starting the kubelet

[control-plane] Using manifest folder "/etc/kubernetes/manifests"

[control-plane] Creating static Pod manifest for "kube-apiserver"

[control-plane] Creating static Pod manifest for "kube-controller-manager"

[control-plane] Creating static Pod manifest for "kube-scheduler"

[etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests"

[wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s

[apiclient] All control plane components are healthy after 13.002889 seconds

[upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace

[kubelet] Creating a ConfigMap "kubelet-config-1.20" in namespace kube-system with the configuration for the kubelets in the cluster

[upload-certs] Skipping phase. Please see --upload-certs

[mark-control-plane] Marking the node master-stg as control-plane by adding the labels "node-role.kubernetes.io/master=''" and "node-role.kubernetes.io/control-plane='' (deprecated)"

[mark-control-plane] Marking the node master-stg as control-plane by adding the taints [node-role.kubernetes.io/master:NoSchedule]

[bootstrap-token] Using token: t4tcwj.22xh9lzstu56qyrb

[bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles

[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to get nodes

[bootstrap-token] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials

[bootstrap-token] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token

[bootstrap-token] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster

[bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace

[kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key

[addons] Applied essential addon: CoreDNS

[addons] Applied essential addon: kube-proxy

 

Your Kubernetes control-plane 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

 

Alternatively, if you are the root user, you can run:

 

  export KUBECONFIG=/etc/kubernetes/admin.conf

 

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/

 

Then you can join any number of worker nodes by running the following on each as root:

 

kubeadm join 192.168.100.119:6443 --token t4tcwj.22xh9lzstu56qyrb \

    --discovery-token-ca-cert-hash sha256:eb3765b58c9140c9a89daf7ea21444ca44a142939ebb93aedad1ebc03202a1d7

 

  - 사용자 계정에서 kubectl 실행을 위해 위의 가이드 내용 그대로 진행을 해보자.

 

$ mkdir -p $HOME/.kube

 

$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config

 

$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

 

  - 잘 설치가 된 것을 확인해보자.

 

$ kubectl get pods --all-namespaces

 

$ kubectl get nodes

 

 

 

  - Pod Network 환경을 맞춰야 하는데, k8s 를 위한 layer 3 환경을 구축해주는 flannel을 사용해보겠다.

    . https://github.com/coreos/flannel/

 

$ kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

 

 

  - coredns가 pending에서 running으로 바뀌었고, flannel이 추가 되었고, Master Node가 Ready 상태가 된 것을 볼 수 있다.

 

 
 
7. Worker Node 셋업
 
  - 기본 환경 설치를 모두 했다면, 아래 명령어만 실행하면 된다.
  - 아래 명령어는 Master Node 설치할 때 나왔던 가이드 밑에 있는 부분 그대로 하면 된다. (각자의 환경에 따라서 실행할 것!!!)
 
$ sudo kubeadm join 192.168.100.119:6443 --token t4tcwj.22xh9lzstu56qyrb \
    --discovery-token-ca-cert-hash sha256:eb3765b58c9140c9a89daf7ea21444ca44a142939ebb93aedad1ebc03202a1d7
 
❯ sudo kubeadm join 192.168.100.119:6443 --token t4tcwj.22xh9lzstu56qyrb \
    --discovery-token-ca-cert-hash sha256:eb3765b58c9140c9a89daf7ea21444ca44a142939ebb93aedad1ebc03202a1d7
 
[preflight] Running pre-flight checks
[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 20.10.1. Latest validated version: 19.03
[preflight] Reading configuration from the cluster...
[preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml'
[kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Starting the kubelet
[kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
 
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
 
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
 
  - Master Node에서 잘 붙었는지 확인해보자.
 
$ kubectl get nodes
 

 

 
 
 
 
 
8. hello kubernetes
 
  - Master Node에서 다음과 같이 deployment를 실행해보자.
 
$ kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1
 
  - 잘 되었는지 확인도 해보자.
 
$ kubectl get deployments
 
$ kubectl get pods -o wide
 

 

  - Worker Node에서 해당 서비스가 잘 되는지 확인해보자.

 

$ curl http://10.244.1.2:8080

 

 

 

 

 

 

여기까지~

 

 

반응형



Minikube를 가지고 놀고 싶은데,

내 PC를 지저분하게 만들기가 싫어서...


최애하는 VirtualBox에 Ubuntu 설치해놓고

그 안에 Minikube를 설치해보고자 한다.



Reference: https://kubernetes.io/ko/docs/tasks/tools/install-minikube/



작업환경

    - Host OS: Windows 10

    - VirtualBox v6.1.12 r139181 (Qt5.6.2)

    - Guest OS: Ubuntu 18.04 Desktop

        . 2 CPU, 8192 Memory




1. 가상화 환경?!


    - "가상화 지원 여부를 확인"하란다. 현재 작업하고 있는 PC가 AMD라서 좀 찝찝한데...

    - VirtualBox의 Guest 환경에서 아래와 같이 "네스티드 VT-x/AMD-V 사용하기(V)"에 체크를 해주었다.




    - 뭔가 나오니까 된 것 같다.


❯ grep -E --color 'vmx|svm' /proc/cpuinfo

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx hypervisor lahf_lm cmp_legacy svm cr8_legacy abm sse4a misalignsse 3dnowprefetch ssbd vmmcall fsgsbase avx2 clflushopt arat nrip_save flushbyasid decodeassists

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid tsc_known_freq pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx hypervisor lahf_lm cmp_legacy svm cr8_legacy abm sse4a misalignsse 3dnowprefetch ssbd vmmcall fsgsbase avx2 clflushopt arat nrip_save flushbyasid decodeassists




2. VirtualBox 설치 ?


    - VirtualBox in VirtualBox ??? 뭔가 이상하지만... 훌륭한 우리 VirtualBox는 이게 된다.


❯ sudo apt install -y virtualbox virtualbox-ext-pack




3. kubectl 설치


    - 제일 먼저 할 것은 현재 최신 버전이 뭔지 확인하는 것이다.


https://storage.googleapis.com/kubernetes-release/release/stable.txt


    - 지금 확인해본 결과는 v1.18.8 이었다.

    - 다운로드 받자. (다운로드 받는 경로나 wget을 사용하는 것은 개인적인 


> cd /srv/install/kubectl


> wget https://storage.googleapis.com/kubernetes-release/release/v1.18.1/bin/linux/amd64/kubectl


    - 설치하자


❯ chmod +x ./kubectl 


❯ sudo cp ./kubectl /usr/local/bin/kubectl


    - 잘 설치되었는지 확인해보자.


❯ kubectl version --client


Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.1", GitCommit:"7879fc12a63337efff607952a323df90cdc7a335", GitTreeState:"clean", BuildDate:"2020-04-08T17:38:50Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}




4. Minikube 설치


    - 다운로드 받아보자


> cd /srv/install/minikube


> wget https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 -O minikube


    - 설치하자


❯ chmod +x ./minikube 


❯ sudo install minikube /usr/local/bin





5. Minikube 실행


    - 실행은 엄청 쉽다


❯ minikube start





6. dashboard


    - minikube는 대시보드도 간단히 제공해준다.


❯ minikube dashboard


🔌  대시보드를 활성화하는 중 ...

🤔  Verifying dashboard health ...

🚀  프록시를 시작하는 중 ...

🤔  Verifying proxy health ...

🎉  Opening http://127.0.0.1:40647/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...

[7090:7090:0822/025314.671219:ERROR:viz_main_impl.cc(150)] Exiting GPU process due to errors during initialization


    - 알아서 Chrome이 뜬다. (아! 개인적인 취향으로 VirtualBox에 Ubuntu 설치하자마자 Chrome을 미리 설치해놨다)





7. docker 설치


    - minikube를 가지고 놀기 위해서는 docker가 필요하다.


❯ sudo apt install -y docker.io


    - 현재 사용자 계정으로 docker를 실행할 수 있도록 하자


❯ sudo usermod -aG docker $USER


❯ newgrp docker


    - 현재 계정을 docker 그룹에 넣어도 바로 적용되지 않는다. 재부팅하기 귀찮아서 newgrp으로 지금 docker 그룹에 속한 것처럼 해버렸다.


    - 잘 설치되었는지 실행해보자. Permission 에러가 안나오면 된다.


❯ docker ps -a


CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES



가지고 노는 것은 다음 기회에~

반응형

+ Recent posts