天天看点

Minikube ubuntu20.04从零安装

首先说明一点,这里安装仅针对单机部署,并不会涉及多节点部署。因此如果想使用多个节点搭建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
           

基础工具安装

  1. 相关镜像源配置

    这里采用清华镜像源,地址为 https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/

    注意选择当前Ubuntu对应的版本,之后将内容覆盖到

    /etc/apt/source.list

    文件

    覆盖完成后执行命令

    apt-get update

  2. 安装curl

    apt-get install curl

  3. 安装contrack

    apt-get install conntrack

组件安装

  1. 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

           

配置到此结束