安装k8s环境说明

  • 环境基于Ubuntu20.04,使用VM虚拟机搭建,这一步不懂可以参考之前的虚拟机安装教程或者网上搜索
  • 鉴于刚开始学习,没有必要直接搭建K8s集群,先安装简单的单机环境即可

安装Docker环境

  • 更新软件源
sudo apt-get update
  • 安装必要的下载和校验工具
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
  • 添加阿里云软件源GPG密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • 添加阿里云软件源
echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  • 再次更新软件源
sudo apt-get update
  • 安装Docker
sudo apt-get install docker-ce docker-ce-cli containerd.io
  • 启动Docker
sudo systemctl enable docker
sudo systemctl start docker
  • 建立Docker用户组
sudo groupadd docker
sudo usermod -aG docker $USER
  • 重启系统测试Hello World
sudo reboot 
docker run --rm hello-world

输出正常的Hello-world信息,即可。

安装Kind

  1. 二进制安装Kind
curl -Lo ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.11.1/kind-linux-amd64
sudo chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind
  • 显示版本
windli@windli:~$ kind --version
kind version 0.11.1
  1. 通过源码安装(需要翻墙,不建议)
  • 获取Docekr Go的版本
windli@windli:~$ docker version
Client: Docker Engine - Community
 Version:           20.10.7
 API version:       1.41
 Go version:        go1.13.15  //Go的版本
 Git commit:        f0df350
 Built:             Wed Jun  2 11:56:38 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.7
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       b0f5bc3
  Built:            Wed Jun  2 11:54:50 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.6
  GitCommit:        d71fcd7d8303cbf684402823e425e9dd2e99285d
 runc:
  Version:          1.0.0-rc95
  GitCommit:        b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

  • 通过Ubuntu snap命令安装
//指定版本安装,和Docker的Go版本保持一致
sudo snap install go --channel=1.13/stable --classic  
//需要翻墙,有可能失败
go get sigs.k8s.io/kind@v0.11.1 

使用kind安装K8s单节点集群

  • 使用kind安装k8s环境
windli@windli:~$ kind create cluster
Creating cluster "kind" ...
 ✓ Ensuring node image (kindest/node:v1.21.1) 🖼 
 ✓ Preparing nodes 📦  
 ✓ Writing configuration 📜 
 ✓ Starting control-plane 🕹️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️️ 
 ✓ Installing CNI 🔌 
 ✓ Installing StorageClass 💾 
Set kubectl context to "kind-kind"
You can now use your cluster with:

kubectl cluster-info --context kind-kind

Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community
  • 如果出现配置KUBECONFIG语句,多输入一句命令,如果没有则不需要输入
export KUBECONFIG="$(kind get kubeconfig-path --name="kind")" //老版本
export KUBECONFIG="$(kind get kubeconfig --name="kind")" //新版本
  • kind找不到kubectl命令解决办法
kubectl: command not found
  • 重新下载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"

chmod +x ./kubectl

sudo mv ./kubectl /usr/local/bin/kubectl
  • 显示kubectl版本,这样显示就安装成功了。
windli@windli:~$ kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.1", GitCommit:"5e58841cce77d4bc13713ad2b91fa0d961e69192", GitTreeState:"clean", BuildDate:"2021-05-13T02:40:46Z", GoVersion:"go1.16.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"13", GitVersion:"v1.13.4", GitCommit:"c27b913fddd1a6c480c229191a087698aa92f0b1", GitTreeState:"clean", BuildDate:"2019-03-20T16:54:39Z", GoVersion:"go1.11.5", Compiler:"gc", Platform:"linux/amd64"}
WARNING: version difference between client (1.21) and server (1.13) exceeds the supported minor version skew of +/-1

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐