系统:CentOS Linux release 8.1.1911
配置主机名
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# hostnamectl set-hostname lan
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# cat /etc/hosts
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
172.18.129.68 lan
关闭swap,我这台阿里云主机么有配置swap空间所以不需要改,步骤我也写一下吧
swapoff -a # 临时关闭swap
[root@k8s-master ~]# cat /etc/fstab # 修改fstab可永久关闭swap
#
# /etc/fstab
# Created by anaconda on Wed May 6 09:09:02 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=a69f20da-ece1-433f-9413-88212ae46a67 /boot xfs defaults 0 0
#/dev/mapper/centos-swap swap swap defaults 0 0
配置内核参数,将桥接流量传递到iptables的链
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# cat > /etc/sysctl.d/k8s.conf < net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# sysctl --system
安装开发者工具包
yum install -y yum-utils device-mapper-persistent-data lvm2
添加docker的yum源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装docker-ce
$ sudo yum makecache fast
$ sudo yum install docker-ce
node: 如果出现以下报错
Error:
Problem: package docker-ce-3:19.03.8-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
- cannot install the best candidate for the job
- package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
- package containerd.io-1.2.13-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
- package containerd.io-1.2.2-3.el7.x86_64 is excluded
- package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
- package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
需要手动安装containerd.io
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# yum install containerd.io-1.2.6-3.3.el7.x86_64.rpm
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# yum -y install docker-ce
配置docker镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://zggyaen3.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
安装kubectl, kubelet, kubeadm
添加阿里k8s源
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# cat < /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
安装
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# yum install kubectl kubelet kubeadm
[root@iZwz9e3t4tj14jzewdtvj8Z ~]# systemctl enable kubelet
初始化集群
[root@lan ~]# kubeadm init --kubernetes-version=1.18.0 \
--apiserver-advertise-address=192.168.22.12 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.11.0.0/16 --pod-network-cidr=10.1.0.0/16
根据记录生成的最后部分内容,创建kubectl
[root@lan ~]# mkdir -p $HOME/.kube
[root@lan ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@lan ~]# chown $(id -u):$(id -g) $HOME/.kube/config
[root@lan ~]# source <(kubectl completion bash)
[root@lan ~]# kubectl get node
NAME STATUS ROLES AGE VERSION
lan NotReady master 50s v1.18.2
查看pod
[root@lan ~]# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-6fcbbfb6fb-56cpv 0/1 Pending 0 15s
kube-system calico-node-x9wqb 0/1 Init:0/3 0 15s
kube-system coredns-7ff77c879f-6jdsj 0/1 Pending 0 73s
kube-system coredns-7ff77c879f-kqpzb 0/1 Pending 0 73s
kube-system etcd-lan 1/1 Running 0 84s
kube-system kube-apiserver-lan 1/1 Running 0 84s
kube-system kube-controller-manager-lan 1/1 Running 0 84s
kube-system kube-proxy-mcrmm 1/1 Running 0 73s
kube-system kube-scheduler-lan 1/1 Running 0 84s
node节点为NotReady,因为corednspod没有启动,缺少网络pod
安装calico网络
[root@lan ~]# kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
[root@lan ~]# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system calico-kube-controllers-6fcbbfb6fb-56cpv 1/1 Running 0 22m
kube-system calico-node-x9wqb 1/1 Running 0 22m
kube-system coredns-7ff77c879f-6jdsj 1/1 Running 0 23m
kube-system coredns-7ff77c879f-kqpzb 1/1 Running 0 23m
kube-system etcd-lan 1/1 Running 0 23m
kube-system kube-apiserver-lan 1/1 Running 0 23m
kube-system kube-controller-manager-lan 1/1 Running 0 23m
kube-system kube-proxy-mcrmm 1/1 Running 0 23m
kube-system kube-scheduler-lan 1/1 Running 0 23m
清除污点
kubectl taint node --all node-role.kubernetes.io/master-
原文链接: https://www.cnblogs.com/sonyy/p/13156439.html