上面的操作流程并不只限于v1.19.14, 更高的版本也可以使用上面的步骤安装.
安装系统
centos7.6 2c 4g
安装需要的软件包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
安装hostnamectl 设置主机名
yum install -y hostnamectl
hostnamectl set-hostname name
关闭并停用防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭SELinux
setenforce 0; sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
关闭swap
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
开启IP转发
sysctl -a |grep -w net.ipv4.ip_forward
打开
echo 1 > /proc/sys/net/ipv4/ip_forward
修改内核参数
cat <<EOF > /etc/sysctl.d/docker.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system
docker的yum源
wget -O /etc/yum.repos.d/CentOS7-Aliyun.repo http://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repowget -O /etc/yum.repos.d/docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum clean all && yum makecache
mkdir -p /etc/docker
加速地址-有就配置
vim /etc/docker/daemon.json
{
"registry-mirrors”: [
"https://xxxxxxx.mirror.aliyuncs.com",
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://dockerhub.azk8s.cn"
],
"exec-opts": [
"native.cgroupdriver=systemd"
]
}
查看docker版本
yum list docker-ce --showduplicates |sort -r
yum install -y docker-ce
安装指定版本
yum install -y docker-ce-19.03.15-3.el7
设置开机自启动
systemctl enable docker
systemctl daemon-reload
启动Docker
systemctl start docker
使用阿里云的kubernetes源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
把master和slave的名字写入到host文件中
cat >> /etc/hosts << EOF
192.168.123.199 k8s-master
192.168.123.151 slave-book
192.168.123.150 slave-1
192.168.123.152 slave-2
EOF
安装kubelet kubeadm kubectl
yum install -y kubelet-1.19.14 kubeadm-1.19.14 kubectl-1.19.14 --disableexcludes=kubernetes
注册kubelet为开机自启动
systemctl enable kubelet.service
查看镜像下载对应的镜像
kubeadm config images list
k8s.gcr.io/kube-apiserver:v1.19.14
k8s.gcr.io/kube-controller-manager:v1.19.14
k8s.gcr.io/kube-scheduler:v1.19.14
k8s.gcr.io/kube-proxy:v1.19.14
k8s.gcr.io/pause:3.2
k8s.gcr.io/etcd:3.4.13-0
k8s.gcr.io/coredns:1.7.0
打印出默认配置
kubeadm config print init-defaults > kubeadm.yaml
cat kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta2
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.123.150 # master的地址
bindPort: 6443
nodeRegistration:
criSocket: /var/run/dockershim.sock
name: k8s-master # master的名称
taints:
- effect: NoSchedule
key: node-role.kubernetes.io/master
---
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta2
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
type: CoreDNS
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers # 使用阿里的镜像仓库(存放google的镜像)
kind: ClusterConfiguration
kubernetesVersion: v1.19.14 # 修改成14版本
networking:
dnsDomain: cluster.local
podSubnet: 10.244.0.0/16 # pod的网段
serviceSubnet: 10.96.0.0/12
scheduler: {}
使用配置文件查看镜像信息
kubeadm config images list --config kubeadm.yaml
使用配置文件提前pull镜像信息
kubeadm config images pull --config kubeadm.yaml
初始化kubeadm
kubeadm init --config kubeadm.yaml
创建kubeconfig文件
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
打印node节点加入集群命令
kubeadm token create --print-join-command
下载Calico的manifest文件
Kubernetes CNI网络最强对比:Flannel、Calico、Canal和Weave
下载地址
curl https://docs.projectcalico.org/v3.10/manifests/calico.yaml -O
安装Calico
Calico和K8S版本映射
kubectl apply -f calico.yaml
删除停止的容器
# 方法1:
sudo docker ps -a | grep Exited | awk {'print $1'} | xargs sudo docker rm
# 方法2:
docker container prune
# Containerd方法1:
crictl ps -a | grep Exited | awk {'print $1'} | xargs crictl rm