MiniKube on Ubuntu 20.04

By | 2022년 11월 30일
Table of Contents

MiniKube on Ubuntu 20.04

Ubuntu 에 MiniKube 를 설치합니다.

참조

Docker 설치

아래 링크를 참조해서 Docker 를 설치해 줍니다.

여기

MiniKube 다운로드

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
  && chmod +x minikube
ls -al minikube

MiniKube 설치

sudo mkdir -p /usr/local/bin/
sudo install minikube /usr/local/bin/

kubelet, kubeadm, kubectl 설치

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sudo sysctl --system
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl

sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

MiniKube 시작

sudo 없이 실행합니다.

minikube start \
    --network-plugin=cni \
    --cni=bridge \
    --container-runtime=containerd \
    --bootstrapper=kubeadm

아래와 같은 로그가 찍히면 정상적으로 실행된 것이다.

......
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
kubectl get nodes

dashboard 활성화

minikube addons list
minikube addons enable dashboard
minikube addons enable metrics-server

minikube dashboard

nginx 설치

Deployment 생성

vi nginx-deployment.yaml
---------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3                 # 3개의 pod
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80   # 컨테이너 포트(pod 포트)
---------------------------
kubectl apply -f nginx-deployment.yaml

3 개의 인스턴스가 실행중인 것을 확인할 수 있습니다.

kubectl get deployments
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           21s

Service 생성

k8s 내부 아이피를 이용해 접속이 가능하지만,
클러스터 외부에서 접속하기 위해서는 서비스를 생성해야 합니다.

vi nginx-svc.yaml
---------------------------
apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  labels:
    run: my-nginx
spec:
  type: NodePort     # 서비스 타입
  ports:
  - nodePort: 31001  # 외부 포트
    port: 8080       # 서비스 포트
    targetPort: 80   # 컨테이너 포트(pod 포트)
    protocol: TCP
    name: http
  selector:
    app: nginx
---------------------------
kubectl apply -f nginx-svc.yaml

nodePort 에 할당된 외부포트 31001 를 통해 nginx 에 접근이 가능합니다.

kubectl get svc | grep my-nginx
my-nginx     NodePort    10.110.214.52   <none>        8080:31001/TCP   69s

minikube ip
192.168.49.2:
curl http://192.168.49.2:31001/

nginx 삭제

# service 삭제
kubectl delete -n default service my-nginx

# deployments 삭제
kubectl get deployments
kubectl delete deployments nginx-deployment

MiniKube 삭제

sudo minikube delete

답글 남기기