0%

Ubuntu安裝Minikube

繼上次的docker安裝今天要繼續部屬kubernetes的內容

簡介

minikube是由google開發的精簡版kubernetes工具
可以簡單的模擬k8s底下的環境運作

安裝容器

kubernetese提供多樣的容器部屬環境
這邊我們選用docker當作容器的底層

請參考之前的文章

安裝kubectl

kubectl是一套管理kubernetes的命令工具

安裝

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 更新套件管理
$ sudo apt update
# 安裝套件倉庫
$ sudo apt 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

deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main

# 更新套件管理
$ sudo apt update
# 安裝kubectl
$ sudo apt install kubectl -y

查看版本

1
2
3
$ kubectl version --short --client

Client Version: v1.22.1

安裝minikube

現在開始安裝主角

安裝

1
2
3
4
5
6
7
8
9
10
# 下載安裝包
$ curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
# 安裝套件
$ sudo dpkg -i minikube_latest_amd64.deb

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

查看版本

1
2
3
4
$ minikube version

minikube version: v1.22.0
commit: a03fbcf166e6f74ef224d4a63be4277d017bb62e

啟動

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ minikube start

😄 minikube v1.22.0 on Ubuntu 20.04 (vbox/amd64)
✨ Automatically selected the docker driver. Other choices: ssh, none
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
💾 Downloading Kubernetes v1.21.2 preload ...
> preloaded-images-k8s-v11-v1...: 502.14 MiB / 502.14 MiB 100.00% 7.08 MiB
> gcr.io/k8s-minikube/kicbase...: 361.08 MiB / 361.09 MiB 100.00% 3.95 MiB
🔥 Creating docker container (CPUs=2, Memory=2200MB) ...
🐳 Preparing Kubernetes v1.21.2 on Docker 20.10.7 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

啟動dashboard

正常的kubernetes的dashboard需要另外安裝的
但是minikube已經自帶dashboard套件只需啟動就行了

1
2
3
4
5
6
7
8
9
10
$ minikube dashboard

🔌 Enabling dashboard ...
▪ Using image kubernetesui/dashboard:v2.1.0
▪ Using image kubernetesui/metrics-scraper:v1.0.4
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:33657/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
👉 http://127.0.0.1:33657/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/

開啟proxy

一般來說啟動dashboard就會自動幫你開啟瀏覽器到dashboard的頁面中了
但是筆者的環境是裝在virtualbox的ubuntu-server底下
所以就需要另外提供外連的方式了

1
2
3
$ kubectl proxy --address='0.0.0.0' --port=8001 --accept-hosts='^*$'

Starting to serve on [::]:8001

這樣就大功告成啦!

補充

安裝過程設定如果出了什麼問題想要重置
我們可刪掉整個minikube設置重來

1
2
3
4
# 刪除minikube環境
$ minikube delete && rm -rf ~/.minikube
# 重啟minikube
$ minikube start