k8s实践

k8s作为分布式集群部署方案,是一个主流的部署方案。

1. 服务器配置

至少准备3台服务器,首先修改服务器名称

hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2

然后关闭防火墙和selinux

systemctl stop firewalld
setenforce 0

将集群ip与名称写入hosts文件

echo '''
10.30.239.157 k8s-master
10.30.239.158 k8s-node1
10.30.239.159 k8s-node2
''' >> /etc/hosts

1. docker安装

容器运行时环境通常是Docker,k8s v1.24之后的般般需要额外安装cri-dockerd,不过目前常用的是1.18左右的版本,只需安装docker。
下载地址:https://download.docker.com/linux/static/stable
将相关部署包放到服务器上,执行如下命令即可完成docker安装

# 解压
# 注意必须重新解压,否则会【Failed to start Docker Application Container Engine】的报错
cd /opt/docker/
tar -zxvf docker-20.10.9.tgz
# 移动到指定目录
cp -p docker/* /usr/bin
# 将预先准备的配置文件复制到指定目录
cp docker.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start docker
systemctl status docker.service

2. cri-dockerd安装

下载cri-dockerd安装包,并设置自启动。

wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.4/cri-dockerd-0.3.4-3.el7.x86_64.rpm
rpm -ivh cri-dockerd-0.3.4-3.el7.x86_64.rpm
systemctl daemon-reload
systemctl enable cri-docker.socket cri-docker
systemctl start cri-docker.socket cri-docker
systemctl status cri-docker.socket

3.Kubernetes安装

3.1 安装 kubectl

curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
# 下载校验文件
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(cat kubectl.sha256)  kubectl" | sha256sum --check
install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client

3.2 安装kubeadm

systemctl stop firewalld
setenforce 0

你可能感兴趣的:(kubernetes,容器,云原生)