Kubernetes 安装

Kubernetes 安装指引

Ubuntu

kubectl 官方源

sudo apt-get update && sudo apt-get install -y apt-transport-https gnupg2
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
# 22.04
curl -sL https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor |
    sudo tee /etc/apt/trusted.gpg.d/packages.cloud.google.com.gpg > /dev/null
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl

minikube 包安装

运行 minikube 依赖谷歌镜像,需要设置代理方可正常使用。Ubuntu 上非 root 用户依赖 docker 运行 minikube:

curl https://get.docker.com | sh

# 允许覆盖安装升级版本
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb

sudo service docker start

# minikube 镜像需要科学上网
su - USERNAME
vim ~/.bashrc
export HTTP_PROXY=http://192.168.1.166:7081
export HTTPS_PROXY=http://192.168.1.166:7081
export NO_PROXY=.163.com,localhost,127.0.0.1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16

# 代理可以在 /etc/environment 中全局设置

# sudo -u USERNAME minikube start   # USER 为非 root 用户名
?  minikube v1.24.0 on Ubuntu 20.04
✨  Automatically selected the docker driver. Other choices: none, ssh
?  Starting control plane node minikube in cluster minikube
?  Pulling base image ...
?  Downloading Kubernetes v1.22.3 preload ...
    > gcr.io/k8s-minikube/kicbase: 355.78 MiB / 355.78 MiB  100.00% 4.68 MiB p/
    > preloaded-images-k8s-v13-v1...: 501.73 MiB / 501.73 MiB  100.00% 6.54 MiB
?  Creating docker container (CPUs=2, Memory=2200MB) ...
?  Found network options:
    ▪ http_proxy=http://
❗  You appear to be using a proxy, but your NO_PROXY environment does not include the minikube IP (192.168.49.2).
?  Please see https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/ for more details
    ▪ https_proxy=http://
    ▪ no_proxy=localhost,10.0.0.0/8,3.0.0.0/8,127.0.0.1,127.0.0.0/8
❗  This container is having trouble accessing https://k8s.gcr.io
?  To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
?  Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
    ▪ env HTTP_PROXY=http://
    ▪ env HTTPS_PROXY=http://
    ▪ env NO_PROXY=localhost,10.0.0.0/8,3.0.0.0/8,127.0.0.1,127.0.0.0/8
    ▪ 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: default-storageclass, storage-provisioner
?  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

minikube 手动安装

可执行文件,安装使用:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube

可执行文件,下载后即可使用:

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube

# 大多 minikube 命令需非 root 用户运行,安装到各用户目录以便 root 误操作
mkdir ~/bin/
install minikube ~/bin/

 用 Docker 开通 minikube 集群需用非 root 用户启动:

$ minikube config set driver docker
$ minikube start

中国用户需要设置代理,让 minikube 从 Google 镜像服务器更新镜像启动服务。

# /etc/environment
http_proxy=
https_proxy=
no_proxy=localhost,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16

从国内镜像安装 

minikube start --vm-driver=podman --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers

CentOS 8

从 Google 源安装

更新 Podman

sudo dnf -y module disable container-tools                                                                                                                                                           
sudo dnf -y install 'dnf-command(copr)'
sudo dnf -y copr enable rhcontainerbot/container-selinux
sudo curl -kL -o /etc/yum.repos.d/devel:kubic:libcontainers:stable.repo https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/CentOS_8/devel:kubic:libcontainers:stable.repo
sudo dnf -y install podman

minikube

CentOS 上 minikube 用 podman 运行,minikube 需用非 root 启动,minikube 安装在相关用户 ~/bin 目录下避免 root 用户误执行:

mkdir ~/bin
cd ~/bin
curl -Lo ~/bin/minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube

# 更新
curl -Lo ~/bin/minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 

# 启动
minikube start --vm-driver=podman 

Windows

通过 Docker 需要设置环境变量后重启。

[Environment]::SetEnvironmentVariable("KUBECONFIG", $HOME + "\.kube\config", [EnvironmentVariableTarget]::Machine)

Azure Kubernetes Service

kubectl

az aks install-cli

中国区

参考素材

示例镜像

云应用

名称 作用
CNCF Landscape 云应用索引
Envoy Proxy 反向代理
Open Tracing/Open Telemetry 访问统计
Prometheus 监控
Author: njun
njun's picture
Updated: 2022/05/26