2020.02.08
1. What is MiniKube ?
- Minikube is a tool that makes it easy to run Kubernetes locally.
https://kubernetes.io/docs/setup/learning-environment/minikube/
- Support OS : Windows, MacOS, Linux
- 지원 Drivers (https://minikube.sigs.k8s.io/docs/drivers/)
- 비교 (https://brennerm.github.io/posts/minikube-vs-kind-vs-k3s.html)
2. Install for MacOS
a. Install kubectl (v1.20.4)
$ brew install kubectl
$ kubectl version --client
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.2", GitCommit:"59603c6e503c87169aea6106f57b9f242f64df89”,
GitTreeState:"clean", BuildDate:"2020-01-23T14:21:54Z", GoVersion:"go1.13.6", Compiler:"gc", Platform:"darwin/amd64”}
$
b. Install a Hypervisor
HyperKit or VirtualBox or Vmware Fusion
Hyperkit is a lightweight macOS virtualization solution built on top of Hypervisor.framework in macOS 10.10 Yosemite and higher.
c. Install Minikube (v1.17.1)
$ brew install minikube
3. Start Minikube and create a cluster
a. hyperkit를 사용할 경우
yoosungjeon@ysjeon-Dev ~ % minikube start --driver=hyperkit --kubernetes-version=1.16.15 # --memory=8g or % minikube config set cpus 4
😄 Darwin 10.15.6 위의 minikube v1.12.3
✨ 유저 환경 설정 정보에 기반하여 hyperkit 드라이버를 사용하는 중
👍 Starting control plane node minikube in cluster minikube
🔥 hyperkit VM (CPUs=2, Memory=4000MB, Disk=20000MB) 를 생성하는 중 ...
🐳 쿠버네티스 v1.15.12 을 Docker 19.03.12 런타임으로 설치하는 중
🔎 Verifying Kubernetes components...
🌟 Enabled addons: default-storageclass, storage-provisioner
🏄 끝났습니다! 이제 kubectl 이 "minikube" 를 사용할 수 있도록 설정되었습니다
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube status
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
yoosungjeon@ysjeon-Dev ~ % minikube profile list
|----------|-----------|---------|---------------|------|----------|---------|-------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes |
|----------|-----------|---------|---------------|------|----------|---------|-------|
| minikube | hyperkit | docker | 192.168.64.24 | 8443 | v1.16.15 | Running | 1 |
|----------|-----------|---------|---------------|------|----------|---------|-------|
yoosungjeon@ysjeon-Dev ~ %
b. Docker를 사용할 경우
yoosungjeon@ysjeon-Dev ~ % minikube start --kubernetes-version=1.15.12 --memory=2g --cpus=2 --profile k8s-1.15.12
😄 [k8s-1.15.12] Darwin 11.2.2 위의 minikube v1.17.1
✨ 자동적으로 docker 드라이버가 선택되었습니다. 다른 드라이버 목록: hyperkit, virtualbox, ssh
👍 k8s-1.15.12 클러스터의 k8s-1.15.12 컨트롤 플레인 노드를 시작하는 중
🔥 Creating docker container (CPUs=2, Memory=2048MB) ...
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, default-storageclass
❗ /usr/local/bin/kubectl is version 1.20.4, which may have incompatibilites with Kubernetes 1.15.12.
▪ Want kubectl v1.15.12? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "k8s-1.15.12" cluster and "default" namespace by default
yoosungjeon@ysjeon-Dev ~ % minikube profile list
|-------------|-----------|---------|---------------|------|----------|---------|-------|
| Profile | VM Driver | Runtime | IP | Port | Version | Status | Nodes |
|-------------|-----------|---------|---------------|------|----------|---------|-------|
| k8s-1.15.12 | docker | docker | 192.168.49.2 | 8443 | v1.15.12 | Running | 1 |
| minikube | hyperkit | docker | 192.168.64.24 | 8443 | v1.16.15 | Running | 1 |
|-------------|-----------|---------|---------------|------|----------|---------|-------|
yoosungjeon@ysjeon-Dev ~ % docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dbea4295484e gcr.io/k8s-minikube/kicbase:v0.0.17 "/usr/local/bin/entr…" 2 minutes ago Up 2 minutes 127.0.0.1:55007->22/tcp,... k8s-1.15.12
yoosungjeon@ysjeon-Dev ~ %
yoosungjeon@ysjeon-Dev ~ % minikube stop --profile k8s-1.15.12
yoosungjeon@ysjeon-Dev ~ % minikube delete --profile k8s-1.15.12
yoosungjeon@ysjeon-Dev ~ % minikube profile minikube
✅ minikube profile was successfully set to minikube
yoosungjeon@ysjeon-Dev ~ %
c. VirtualBox를 사용할 경우
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube start --driver=virtualbox --profile VirtualBox
😄 minikube v1.7.1 on Darwin 10.15.3
✨ Using the virtualbox driver based on user configuration
🔥 Creating virtualbox VM (CPUs=2, Memory=2000MB, Disk=20000MB) ...
🐳 Preparing Kubernetes v1.17.2 on Docker '19.03.5' ...
🚜 Pulling images ...
🚀 Launching Kubernetes ...
🌟 Enabling addons: default-storageclass, storage-provisioner
⌛ Waiting for cluster to come online ...
🏄 Done! kubectl is now configured to use "minikube"
ysjeon-MacBook-Pro:~ yoosungjeon$
- Oracle VM VirtualBox 관리자를 실행해 보면 “minikube” VM이 생성된 것을 확인 할 수 있음
4. K8s 사용하기
ysjeon-MacBook-Pro:~ yoosungjeon$ kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.10
deployment.apps/hello-minikube created
ysjeon-MacBook-Pro:~ yoosungjeon$ kubectl expose deployment hello-minikube --type=NodePort --port=8080
service/hello-minikube exposed
ysjeon-MacBook-Pro:~ yoosungjeon$ kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/hello-minikube NodePort 10.111.68.233 <none> 8080:31763/TCP 12s
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 131m
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube ip
192.168.99.100
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube service hello-minikube --url
ysjeon-MacBook-Pro:~ yoosungjeon$ curl http://192.168.99.100:31763
Hostname: hello-minikube-797f975945-twnzn
...
ysjeon-MacBook-Pro:~ yoosungjeon$ kubectl delete services hello-minikube
ysjeon-MacBook-Pro:~ yoosungjeon$ kubectl delete deployment hello-minikube
5. NodePort
a. hyperkit를 사용할 경우
yoosungjeon@ysjeon-Dev ~ % k get svc -n default
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.98.91.41 <none> 8080:30782/TCP 73m
hello-minikube1 NodePort 10.99.189.136 <none> 8080:31329/TCP 30s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 74m
yoosungjeon@ysjeon-Dev ~ % minikube service list
|-------------|-----------------|--------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-------------|-----------------|--------------|---------------------------|
| default | hello-minikube | 8080 | http://192.168.64.8:30782 |
| default | hello-minikube1 | 8080 | http://192.168.64.8:31329 |
| default | kubernetes | No node port | |
| kube-system | kube-dns | No node port | |
|-------------|-----------------|--------------|---------------------------|
yoosungjeon@ysjeon-Dev ~ %
b. Docker를 사용할 경우
yoosungjeon@ysjeon-Dev ~ % k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.97.6.101 <none> 8080:31399/TCP 83s
hello-minikube1 NodePort 10.101.192.61 <none> 8080:32107/TCP 79s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 116s
yoosungjeon@ysjeon-Dev ~ % minikube service hello-minikube &
|-----------|----------------|-------------|--------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|--------------------------|
| default | hello-minikube | 8080 | http://172.17.0.3:31399 |
|-----------|----------------|-------------|--------------------------|
🏃 Starting tunnel for service hello-minikube.
|-----------|----------------|-------------|--------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|----------------|-------------|--------------------------|
| default | hello-minikube | | http://127.0.0.1:53031 |
|-----------|----------------|-------------|--------------------------|
🎉 Opening service default/hello-minikube in default browser...
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
[2] 65626
yoosungjeon@ysjeon-Dev ~ % minikube service hello-minikube1 &
|-----------|-----------------|-------------|-------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-----------------|-------------|-------------------------|
| default | hello-minikube1 | 8080 | http://172.17.0.3:32107 |
|-----------|-----------------|-------------|-------------------------|
🏃 Starting tunnel for service hello-minikube1.
|-----------|-----------------|-------------|-------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|-----------------|-------------|-------------------------|
| default | hello-minikube1 | | http://127.0.0.1:53051 |
|-----------|-----------------|-------------|-------------------------|
🎉 Opening service default/hello-minikube1 in default browser...
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
[3] 65635
yoosungjeon@ysjeon-Dev ~ % minikube service list
|-------------|-----------------|--------------|-----|
| NAMESPACE | NAME | TARGET PORT | URL |
|-------------|-----------------|--------------|-----|
| default | hello-minikube | 8080 | |
| default | hello-minikube1 | 8080 | |
| default | kubernetes | No node port | |
| kube-system | kube-dns | No node port | |
|-------------|-----------------|--------------|-----|
yoosungjeon@ysjeon-Dev ~ %
6. Stop MiniKube and delete a cluster
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube stop
✋ Stopping "minikube" in virtualbox ...
🛑 "minikube" stopped.
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube delete
🔥 Deleting "minikube" in virtualbox ...
💀 Removed all traces of the "minikube" cluster.
ysjeon-MacBook-Pro:~ yoosungjeon$
7. MiniKube 활용하기
a. ssh 접속
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube ssh
$
b. Minikube config (CPU/Memory) 조정
yoosungjeon@ysjeon-Dev elastic-cloud-kubernetes % minikube config set memory 6000 # minikube config set cpus 4
❗ These changes will take effect upon a minikube delete and then a minikube start
yoosungjeon@ysjeon-Dev elastic-cloud-kubernetes % minikube config view
- memory: 6000
yoosungjeon@ysjeon-Dev elastic-cloud-kubernetes % minikube ssh
$ lscpu | grep CPU
CPU op-mode(s): 32-bit, 64-bit
CPU(s): 2
…
$ free -h
total used free shared buff/cache available
Mem: 3.8Gi 2.7Gi 125Mi 544Mi 990Mi 349Mi
Swap: 0B 0B 0B
$
c. local docker에 MiniKube내의 docker를 연결
ysjeon-MacBook-Pro:~ yoosungjeon$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube docker-env .
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.64.6:2376"
export DOCKER_CERT_PATH="/Users/yoosungjeon/.minikube/certs"
export MINIKUBE_ACTIVE_DOCKERD="minikube"
# Please run command bellow to point your shell to minikube's docker-daemon :
# eval $(minikube -p minikube docker-env)
ysjeon-MacBook-Pro:~ yoosungjeon$ eval $(minikube -p minikube docker-env)
ysjeon-MacBook-Pro:~ yoosungjeon$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d7a2c720d280 70f311871ae1 "/coredns -conf /etc…" 9 minutes ago Up 9 minutes k8s_coredns_coredns-6955765f44-ll58n_kube-system_eccda56f-8f64-440a-a5fc-29cfd5773873_0
d056a4860dc5 4689081edb10 "/storage-pro
...
ysjeon-MacBook-Pro:~ yoosungjeon$
8. k8s dashboard
ysjeon-MacBook-Pro:streamer yoosungjeon$ minikube addons list
|-----------------------------|----------|--------------|
| ADDON NAME | PROFILE | STATUS |
|-----------------------------|----------|--------------|
| dashboard | minikube | disabled |
| default-storageclass | minikube | enabled ✅ |
| efk | minikube | disabled |
| freshpod | minikube | disabled |
| gvisor | minikube | disabled |
| helm-tiller | minikube | disabled |
| ingress | minikube | disabled |
| ingress-dns | minikube | disabled |
| istio | minikube | disabled |
| istio-provisioner | minikube | disabled |
| logviewer | minikube | disabled |
| metrics-server | minikube | disabled |
| nvidia-driver-installer | minikube | disabled |
| nvidia-gpu-device-plugin | minikube | disabled |
| registry | minikube | disabled |
| registry-creds | minikube | disabled |
| storage-provisioner | minikube | enabled ✅ |
| storage-provisioner-gluster | minikube | disabled |
|-----------------------------|----------|--------------|
ysjeon-MacBook-Pro:~ yoosungjeon$ minikube dashboard
🔌 Enabling dashboard ...
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:54887/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser…
9. metallb
yoosungjeon@ysjeon-Dev ~ % minikube addons enable metallb
🌟 'metallb' 애드온이 활성화되었습니다
yoosungjeon@ysjeon-Dev ~ % k get pod -n metallb-system
NAME READY STATUS RESTARTS AGE
controller-65895b47d4-fmm25 1/1 Running 0 3m45s
speaker-c87x9 1/1 Running 0 3m45s
yoosungjeon@ysjeon-Dev ~ % minikube ip
192.168.64.24
yoosungjeon@ysjeon-Dev ~ % minikube addons configure metallb
-- Enter Load Balancer Start IP: 192.168.64.25
-- Enter Load Balancer End IP: 192.168.64.30
✅ 이 성공적으로 설정되었습니다
yoosungjeon@ysjeon-Dev ~ % k describe configmaps config -n metallb-system | egrep 'address-pools' -A5
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.64.25-192.168.64.30
yoosungjeon@ysjeon-Dev ~ %
yoosungjeon@ysjeon-Dev ~ % k get svc -n gitlab | egrep 'NAME|gitlab-nginx-ingress-controller'
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
gitlab-nginx-ingress-controller NodePort 10.105.229.237 <none> 80:30869/TCP,443:30842/TCP,22:31555/TCP 4d18h
gitlab-nginx-ingress-controller-metrics ClusterIP 10.109.21.224 <none> 9913/TCP 4d18h
yoosungjeon@ysjeon-Dev ~ % k edit svc gitlab-nginx-ingress-controller -n gitlab
…
type: LoadBalancer # Before: NodePort
…
yoosungjeon@ysjeon-Dev ~ % k get svc -n gitlab | egrep 'NAME|gitlab-nginx-ingress-controller'
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
gitlab-nginx-ingress-controller LoadBalancer 10.105.229.237 192.168.64.25 80:30869/TCP,443:30842/TCP,22:31555/TCP 4d18h
gitlab-nginx-ingress-controller-metrics ClusterIP 10.109.21.224 <none> 9913/TCP 4d18h
yoosungjeon@ysjeon-Dev ~ %
'Kubernetes > Install' 카테고리의 다른 글
MetalLB (0) | 2021.09.15 |
---|---|
keepalived, haproxy for K8s (0) | 2021.09.15 |
K8s 구성 - KinD on MacOS (0) | 2021.09.14 |
K8s 구성 - Single on GCE (0) | 2021.09.14 |
K8s 구성 - HA K8s on bare-metal server (0) | 2021.09.14 |
댓글