https://blog.bwcxtech.com/
需要双核cpu的做master
systemctl stop firewalld && systemctl disable firewalld && sed -i “s/SELINUX=enforcing/SELINUX=disabled/g” /etc/sysconfig/selinux && setenforce 0
sed -i s@^\(SELINUX=\).*@\ldisabled@
/etc/sysconfig/selinux
systemctl restart chronyd && systemctl status chronyd
cat /etc/chrony.conf 查看时间服务器
vi /etc/hosts
10.0.0.25 master.ckafk2.com master
10.0.0.22 node1.ckafk2.com node1
10.0.0.24 node2.ckafk2.com node2
swap -a 临时禁用交换分区
vi /etc/fstab 永久关闭方法,在swap前加#
ls /usr/lib/modules
uname -r
cd /usr/lib/modules/* cd ./ku/kernel/net/netfilter/ipvs
启用ipvs内核模块(稍后改)
cd /etc/yum.repos.d/ && curl -o ali-docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce -y
systemctl daemon-reload && systemctl start docker && systemctl enable docker
docker info
vim /etc/yum.repo.d/kubernetes.repo
[kubernetes]
name=Kubernetes Repository
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enable=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
yum install kubeadm kubectl kubelet -y
如果swap未有禁用,则编辑 vi /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS=“–fail-swap-on=false”
kubeadm 部署集群
kubeadm -h 会看到如下
alpha Kubeadm experimental sub-commands(实验的,不稳定)
completion Output shell completion code for the specified shell (bash or zsh) (shell自动补全的)
config Manage configuration for a kubeadm cluster persisted in a ConfigMap in the cluster(默认配置,kubeadm config -h, kubeadm config print init-defaults)
help Help about any command
init Run this command in order to set up the Kubernetes control plane(只有当一个集群的master节点才会使用到此init)
join Run this on any machine you wish to join an existing cluster(这是node节点加入主节点时用的)
reset Run this to revert any changes made to this host by ‘kubeadm init’ or ‘kubeadm join’(无论是主还是从节点,想删了初始化回到原始状态,用reset重置)
token Manage bootstrap tokens
upgrade Upgrade your cluster smoothly to a newer version with this command(版本升级)
version Print the version of kubeadm
kubeadm init --kubernetes-version=“v1.15.2” --pod-network-cidr=“10.244.0.0/16” --dry-run
提示交换分区警告
kubeadm init --kubernetes-version=“v1.15.2” --pod-network-cidr=“10.244.0.0/16” --dry-run --ignore-preflight-errors=Swap
提示/proc/sys/net/bridge/bridge-nf-call-iptables不是1则
echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
此时可以开始初始化kubeadm集群主机了,可以直接去掉dry run(得,下载慢)
也可以先下载镜像(得,推荐),但我的电脑此处报错无法下载,因为没有
查看要下载哪些 kubeadm config images list
k8s.gcr.io/kube-apiserver:v1.15.2
k8s.gcr.io/kube-controller-manager:v1.15.2
k8s.gcr.io/kube-scheduler:v1.15.2
k8s.gcr.io/kube-proxy:v1.15.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd:3.3.10
k8s.gcr.io/coredns:1.3.1
然后下载 kubeadm config images pull
docker pull mirrorgooglecontainers/kube-apiserver:v1.15.2
docker pull mirrorgooglecontainers/kube-controller-manager:v1.15.2
docker pull mirrorgooglecontainers/kube-scheduler:v1.15.2
docker pull mirrorgooglecontainers/kube-proxy:v1.15.2
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/etcd:3.3.10
docker pull coredns/coredns:1.3.1
docker pull quay.io/coreos/flannel:v0.11.0-amd64
registry.cn-hangzhou.aliyuncs.com/google_containers
kubeadm init --kubernetes-version=“v1.15.2” --pod-network-cidr=“10.244.0.0/16” --ignore-preflight-errors=Swap
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl create -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
node01
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.2
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
registry.cn-hangzhou.aliyuncs.com/google_containers
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.2 k8s.gcr.io/kube-apiserver:v1.15.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.2 k8s.gcr.io/kube-controller-manager:v1.15.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.2 k8s.gcr.io/kube-scheduler:v1.15.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.2 k8s.gcr.io/kube-proxy:v1.15.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubeadm join 10.0.0.25:6443 --token a30edt.uwgmifdb29x3vt4n
–discovery-token-ca-cert-hash sha256:fc084e7d9b0f0ccce47a7c42bb3bde2c92194f5ee218e711dab142398bc9b1b9