从零开始创建k8s集群(一)

本文是按照k8s官网进行的创建k8s集群

官网地址:https://kubernetes.io/docs/setup/production-environment/container-runtimes/

环境是ubuntu 16.04系统

1.安装Docker


# 安装 Docker CE
##设置docker 仓库:
### apt通过HTTPS使用仓库下载安装包
apt-get update && apt-get install apt-transport-https ca-certificates curl software-properties-common

### 获取Docker官方安装秘钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

### 添加Docker apt仓库.
add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

## 安装Docker CE.
apt-get update && apt-get install docker-ce=18.06.2~ce~3-0~ubuntu

# 建立daemon.
cat > /etc/docker/daemon.json <<EOF
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2"
}
EOF

mkdir -p /etc/systemd/system/docker.service.d

# 重启docker.
systemctl daemon-reload
systemctl restart docker

2.安装CRI-O(如何安装docker  可以不安装cri-o)

crio简介

Kubernetes 项目推出了容器运行时接口Container Runtime Interface(CRI):这是一个插件接口,它让 kubelet(用于创建 pod 和启动容器的集群节点代理)有使用不同的兼容 OCI 的容器运行时的能力,而不需要重新编译 Kubernetes。在这项工作的基础上,CRI-O 项目(原名 OCID)准备为 Kubernetes 提供轻量级的运行时。

CRI-O 允许你直接从 Kubernetes 运行容器,而不需要任何不必要的代码或工具。只要容器符合 OCI 标准,CRI-O 就可以运行它,去除外来的工具,并让容器做其擅长的事情:加速你的新一代原生云程序。

就是抽象出来的容器命令接口,有了他各种容器只要满足这些接口k8s就可以随意切换各种容器。

预先条件

#使用modprobe命令加载overlay存储模块
modprobe overlay
#使用modprobe命令加载br_netfilter防火墙模块
modprobe br_netfilter

#建立需要的 sysctl 参数, 这些会重启启动.
cat > /etc/sysctl.d/99-kubernetes-cri.conf <<EOF
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

sysctl --system

安装CRI-O


# 安装前先添加仓库
apt-get update
apt-get install software-properties-common

add-apt-repository ppa:projectatomic/ppa
apt-get update

# 安装crio(官网给的是cri-o-1.13,但是仓库中找不到,换成cri-o-1.12可以找到)
apt-get install cri-o-1.12

启动CRI-O

systemctl start crio

3.安装Containerd

预先条件

#使用modprobe命令加载overlay存储模块
modprobe overlay
#使用modprobe命令加载br_netfilter防火墙模块
modprobe br_netfilter

#建立需要的 sysctl 参数, 这些会重启启动.
cat > /etc/sysctl.d/99-kubernetes-cri.conf <<EOF
net.bridge.bridge-nf-call-iptables  = 1
net.ipv4.ip_forward                 = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF

sysctl --system

安装containerd


# 安装containerd
## 建立仓库repository
### apt通过HTTPS使用仓库下载安装包
apt-get update && apt-get install -y apt-transport-https ca-certificates curl software-properties-common

### 添加Docker官方下载秘钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -

### 添加docker apt仓库
add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
    $(lsb_release -cs) \
    stable"

## 安装containerd
apt-get update && apt-get install -y containerd.io

# 配置containerd
mkdir -p /etc/containerd
containerd config default > /etc/containerd/config.toml

# 重启 containerd
systemctl restart containerd

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值