K8s集群部署

关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭selinux
setenforce 0
s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
关闭swap
swapoff -a
sed -i "/swap/ s/^/#/" /etc/fstab
-----------------------------------------------------------
网络配置(可选)
modprobe br_netfilter
echo "br_netfilter" > /etc/modules-load.d/br_netfilter.conf
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system

echo "1" > /proc/sys/net/bridge/bridge-nf-call-iptables
echo "1" > /proc/sys/net/bridge/bridge-nf-call-ip6tables
-----------------------------------------------------------
更换yum源
cd /etc/yum.repos.d && \
mv CentOS-Base.repo CentOS-Base.repo.bak && \
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
yum clean all && \
yum makecache
配置k8s源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
配置docker-ce源
cd /etc/yum.repos.d/
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
安装k8s组件
yum install -y docker-ce kubelet kubeadm kubectl
更换docker源
mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://wgcscytr.mirror.aliyuncs.com"]
}
EOF
启动docker和管理工具
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
查看k8s初始化需要的静像
kubeadm config images list
获取静像
kubeadm config images list |sed -e 's/^/docker pull /g' -e 's#k8s.gcr.io#registry.cn-hangzhou.aliyuncs.com/google_containers#g' |sh -x

docker images |grep registry.cn-hangzhou.aliyuncs.com/google_containers |awk '{print "docker tag ",$1":"$2,$1":"$2}' |sed -e 's#registry.cn-hangzhou.aliyuncs.com/google_containers#k8s.gcr.io#2' |sh -x

docker images |grep registry.cn-hangzhou.aliyuncs.com/google_containers |awk '{print "docker rmi ", $1":"$2}' |sh -x
k8s初始化
kubeadm init --kubernetes-version=v1.15.3 --pod-network-cidr=10.244.0.0/16
增加配置信息
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
部署flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
查看集群状态
kubectl get nodes
查看主节点详细信息
kubectl describe node master.k8s.com

在子节点中安装k8s组件
yum install -y docker-ce kubelet kubeadm
子节点加入集群
kubeadm join 192.168.2.121:6443 --token cnj2cq.o4wp6jif8uoxjlgd \
--discovery-token-ca-cert-hash sha256:8fe3b3cc03a44e47eb78e28ba021dd0d25198f5764e7a6387a9546f01fce3338
从主节点导出静像
docker save 232b > kube-proxy.tar
docker save da86 > pause.tar
docker save ff28 > flannel.tar
导入从主节点导出的静像
docker load < flannel.tar
docker load < kube-proxy.tar
docker load < pause.tar
修改静像标签
docker tag 232b k8s.gcr.io/kube-proxy:v1.15.3
docker tag da86 k8s.gcr.io/pause:3.1
docker tag ff28 quay.io/coreos/flannel:v0.11.0-amd64

posted @ 2019-09-04 14:33  BicycleBoy  阅读(290)  评论(0编辑  收藏  举报