1.系统初始化和镜像准备
#!/bin/bash
echo "1.系统初始化"
setenforce 0
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
systemctl disable firewalld
systemctl stop firewalld
swapoff -a
sysctl -p
sed -i 's/.*swap.*/#&/' /etc/fstab
iptables -F && iptables -t nat -F && iptables -t mangle -F && iptables -X
cat > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
echo "2.添加docker和kuberentes yum源"
cd /etc/yum.repos.d
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
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
echo "3.检查yum可用性"
yum repolistj
echo "4.安装kubelet kubectl kubeadm docker-ce"
yum install -y kubelet-1.15.3-0.x86_64 kubectl-1.15.3-0.x86_64 kubeadm-1.15.3-0.x86_64 docker-ce-18.09.9-3.el7.x86_64
systemctl enable docker.service
systemctl enable kubelet.service
systemctl start docker.service
echo "5.下载相关镜像"
docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.15.3
docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.15.3 k8s.gcr.io/kube-apiserver:v1.15.3
docker rmi mirrorgooglecontainers/kube-apiserver-amd64:v1.15.3
docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.15.3
docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.15.3 k8s.gcr.io/kube-controller-manager:v1.15.3
docker rmi mirrorgooglecontainers/kube-controller-manager-amd64:v1.15.3
docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.15.3
docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.15.3 k8s.gcr.io/kube-scheduler:v1.15.3
docker rmi mirrorgooglecontainers/kube-scheduler-amd64:v1.15.3
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.15.3
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.15.3 k8s.gcr.io/kube-proxy:v1.15.3
docker rmi mirrorgooglecontainers/kube-proxy-amd64:v1.15.3
docker pull mirrorgooglecontainers/etcd-amd64:3.3.10
docker tag mirrorgooglecontainers/etcd-amd64:3.3.10 k8s.gcr.io/etcd:3.3.10
docker rmi mirrorgooglecontainers/etcd-amd64:3.3.10
docker pull mirrorgooglecontainers/pause-amd64:3.1
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1
docker rmi mirrorgooglecontainers/pause-amd64:3.1
docker pull truthbean/coredns:1.3.1
docker tag truthbean/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
docker rmi truthbean/coredns:1.3.1
echo finished.
2.kubernetes初始化
[root@node1 ~]# kubeadm init --kubernetes-version=v1.15.3 \
--pod-network-cidr=10.244.0.0/16 \
--service-cidr=10.96.0.0/12 \
--ignore-preflight-errors=Swap
[init] Using Kubernetes version: v1.15.3
·····此处省略n个字
[addons] Applied essential addon: kube-proxy
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 172.17.32.11:6443 --token njr1mj.8fcui8ckhwyb858a \
--discovery-token-ca-cert-hash sha256:b32dc84254125e2b2995f48e31f5ae0ee6aaeb535be59a333ca792b0714eee15
#拷贝证书到默认目录
[root@node1 ~]# mkdir -p $HOME/.kube
[root@node1 ~]# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
#添加master节点
[root@node1 ~]# kubeadm join 172.17.32.11:6443 --token njr1mj.8fcui8ckhwyb858a \
--discovery-token-ca-cert-hash sha256:b32dc84254125e2b2995f48e31f5ae0ee6aaeb535be59a333ca792b0714eee15
网友评论