메뉴 닫기

Minikube 로 Nginx 배포

“Minikube 로 Nginx 배포”


Minikube 는 단일 노드 Kubernetes Cluster를 가상머신에서 구동하는 도구입니다.

minikube를 이용하면 손쉽게 로컬에서 Kubernetes Cluster를 만들 수 있습니다.

[개  요]

✅ 종    류 : 프로그램/툴 설치

✅ 난이도 : ⭐

✅ 내용요약 : MiniKube를 사용하여 Nginx 배포

✅ 테스트환경 : ubuntu 22.04

✅ 관련직무 : 시스템&클라우드 엔지니어

1. docker 설치


1️⃣ docker 설치

curl -fsSL https://get.docker.com | sudo sh

[실행화면]

# Executing docker install script, commit: e5543d473431b782227f8908005543bb4389b8de
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c install -m 0755 -d /etc/apt/keyrings
+ sh -c curl -fsSL “https://download.docker.com/linux/ubuntu/gpg” | gpg –dearmor –yes -o /etc/apt/keyrings/docker.gpg
+ sh -c chmod a+r /etc/apt/keyrings/docker.gpg
+ sh -c echo “deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable” > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin >/dev/null
+ sh -c docker version
Client: Docker Engine – Community
Version: 24.0.7
API version: 1.43
Go version: go1.20.10
Git commit: afdd53b
Built: Thu Oct 26 09:07:41 2023
OS/Arch: linux/amd64
Context: default

Server: Docker Engine – Community
Engine:
Version: 24.0.7
API version: 1.43 (minimum version 1.12)
Go version: go1.20.10
Git commit: 311b9ff
Built: Thu Oct 26 09:07:41 2023
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.26
GitCommit: 3dd1e886e55dd695541fdcd67420c2888645a495
runc:
Version: 1.1.10
GitCommit: v1.1.10-0-g18a0cb0
docker-init:
Version: 0.19.0
GitCommit: de40ad0

================================================================================

To run Docker as a non-privileged user, consider setting up the
Docker daemon in rootless mode for your user:

dockerd-rootless-setuptool.sh install

Visit https://docs.docker.com/go/rootless/ to learn about rootless mode.

To run the Docker daemon as a fully privileged service, but granting non-root
users access, refer to https://docs.docker.com/go/daemon-access/

WARNING: Access to the remote API on a privileged Docker daemon is equivalent
to root access on the host. Refer to the ‘Docker daemon attack surface’
documentation for details: https://docs.docker.com/go/attack-surface/

================================================================================

docker ps

[실행화면]

CONTAINER   ID   IMAGE   COMMAND   CREATED   STATUS   PORTS   NAMES

2. Minikube 설치


1️⃣ Minikube 설치

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb

dpkg -i minikube_latest_amd64.deb

 

[실행화면]

Selecting previously unselected package minikube.
(Reading database … 69908 files and directories currently installed.)
Preparing to unpack minikube_latest_amd64.deb …
Unpacking minikube (1.32.0-0) …
Setting up minikube (1.32.0-0) …

minikube start

 

[실행화면]

😄 minikube v1.32.0 on Ubuntu 22.04 (kvm/amd64)
✨ Automatically selected the docker driver. Other choices: none, ssh
🛑 The “docker” driver should not be used with root privileges. If you wish to continue as root, use –force.
💡 If you are running minikube within a VM, consider using –driver=none:
📘 https://minikube.sigs.k8s.io/docs/reference/drivers/none/

❌ Exiting due to DRV_AS_ROOT: The “docker” driver should not be used with root privileges.

 

해당 error는 docker를 root권한으로 사용하려 했을 경우 나옵니다.

따라서 전용 사용자 계정을 추가로 생성해줘야 합니다.

2️⃣ 사용자 계정 생성

useradd -m -d /home/smileserv -s /bin/bash smileserv // /home/smilserv가 home 디렉터리인 smileserv 사용자 생성 
passwd smileserv // smileserv 비밀번호 설정
usermod -aG sudo smileserv // smileserv 계정 sudo 권한
usermod -aG docker smileserv // smileserv 계정 docker 권한
su smileserv

3️⃣ MiniKube 설치

Minikube start

[실행화면]

smileserv@minikube:~$ minikube start
😄 minikube v1.32.0 on Ubuntu 22.04 (kvm/amd64)
✨ Automatically selected the docker driver
📌 Using Docker driver with root privileges
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image …
💾 Downloading Kubernetes v1.28.3 preload …
> preloaded-images-k8s-v18-v1…: 403.35 MiB / 403.35 MiB 100.00% 29.60 M
> gcr.io/k8s-minikube/kicbase…: 453.90 MiB / 453.90 MiB 100.00% 29.23 M
🔥 Creating docker container (CPUs=2, Memory=2200MB) …
🐳 Preparing Kubernetes v1.28.3 on Docker 24.0.7 …
▪ Generating certificates and keys …
▪ Booting up control plane …
▪ Configuring RBAC rules …
🔗 Configuring bridge CNI (Container Networking Interface) …
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🔎 Verifying Kubernetes components…
🌟 Enabled addons: storage-provisioner, default-storageclass
💡 kubectl not found. If you need it, try: ‘minikube kubectl — get pods -A’
🏄 Done! kubectl is now configured to use “minikube” cluster and “default” namespace by default

3. kubectl 설치


1️⃣ kubectl 설치

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version

[실행화면]

smileserv@minikube:~$ kubectl version
Client Version: v1.29.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.3

4. nginx yaml 작성


vim nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deploy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx-app
  template:
    metadata:
      labels:
        app: nginx-app
    spec:
      containers:
      – name: nginx-container
        image: nginx:latest
        ports:
        – containerPort: 80
vim nginx-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  type: NodePort
  selector:
    app: nginx-app
  ports:
    – targetPort: 80
      port: 80
      nodePort: 30080

5. 배포


kubectl apply -f ./nginx-deployment.yaml

[실행화면]

smileserv@minikube:~$ kubectl apply -f ./nginx-deployment.yaml
deployment.apps/nginx-deploy created

kubectl get all
kubectl apply -f ./nginx-service.yaml

[실행화면]

smileserv@minikube:~$ kubectl apply -f ./nginx-service.yaml
service/nginx-service created

kubectl get all
minikube service nginx-service --url

[실행화면]

smileserv@minikube:~$ minikube service nginx-service –url
http://192.168.49.2:30080

 

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x