首先說明一點,這裡安裝僅針對單機部署,并不會涉及多節點部署。是以如果想使用多個節點搭建k8s請不要參考此教程,首先展示一下本機基礎環境
[email protected]:~# cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.2 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
基礎工具安裝
-
相關鏡像源配置
這裡采用清華鏡像源,位址為 https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/
注意選擇目前Ubuntu對應的版本,之後将内容覆寫到
/etc/apt/source.list
檔案
覆寫完成後執行指令
apt-get update
- 安裝curl
apt-get install curl
- 安裝contrack
apt-get install conntrack
元件安裝
- kubectl安裝
curl -LO "https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl"
如果你ubuntu叢集無法執行這個指令,或者執行非常慢可以直接用能上外網主機通路上述網址,之後會自動下載下傳檔案,然後上傳到ubuntu主機,請确定下載下傳完成後繼續下面步驟
将下載下傳檔案放到指定目錄,這個可以任意
[email protected]:/home/iris/k8s/kubectl# pwd
/home/iris/k8s/kubectl
之後配置環境變量,具體為修改/etc/profile檔案
[email protected]:~# tail -n 2 /etc/profile
export PATH=$PATH:/home/iris/k8s/kubectl:/home/iris/k8s/minikube
後面是minikube位置,可以先配置上
2. minikube安裝
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
同樣的,你也可以通過其他電腦下載下傳然後上傳至ubuntu主機,本次我的安裝位置如下
[email protected]:/home/iris/k8s/minikube# pwd
/home/iris/k8s/minikube
[email protected]:/home/iris/k8s/minikube# ll
total 58404
drwxr-xr-x 2 root root 4096 3月 27 23:59 ./
drwxr-xr-x 4 root root 4096 3月 27 23:58 ../
-rwxr-xr-x 1 root root 59794699 3月 27 23:58 minikube*
值得一提是下載下傳下的檔案名稱為
minikube-linux-amd64
,在檔案目錄下使用
mv minikube-linux-amd64 minikube
指令改為minikube
3. docker安裝
這一部分可以參考官方教程 https://docs.docker.com/engine/install/ubuntu/
本次使用
Install using the repository
開頭的安裝方式
啟動
啟動之前,使用指令
source /etc/profile
指令重新整理環境變量配置,之後執行如下指令
[email protected]:/home/iris/k8s# minikube start --vm-driver=none --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
* minikube v1.18.1 on Ubuntu 20.04
* Using the none driver based on existing profile
* Starting control plane node minikube in cluster minikube
* Restarting existing none bare metal machine for "minikube" ...
* OS release is Ubuntu 20.04.2 LTS
* Preparing Kubernetes v1.20.2 on Docker 20.10.5 ...
- kubelet.resolv-conf=/run/systemd/resolve/resolv.conf
> kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubelet: 108.73 MiB / 108.73 MiB [-------------] 100.00% 4.35 MiB p/s 26s
- Generating certificates and keys ...
- Booting up control plane ...
- Configuring RBAC rules ...
* Configuring local host environment ...
*
! The 'none' driver is designed for experts who need to integrate with an existing VM
* Most users should use the newer 'docker' driver instead, which does not require root!
* For more information, see: https://minikube.sigs.k8s.io/docs/reference/drivers/none/
*
! kubectl and minikube configuration will be stored in /root
! To use kubectl or minikube commands as your own user, you may need to relocate them. For example, to overwrite your own settings, run:
*
- sudo mv /root/.kube /root/.minikube $HOME
- sudo chown -R $USER $HOME/.kube $HOME/.minikube
*
* This can also be done automatically by setting the env var CHANGE_MINIKUBE_NONE_USER=true
* Verifying Kubernetes components...
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/k8s-minikube/storage-provisioner:v4 (global image repository)
* Enabled addons: storage-provisioner, default-storageclass
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
配置到此結束