码迷,mamicode.com
首页 > Web开发 > 详细

kubeadm安装kubernetes集群

时间:2019-04-11 16:14:03      阅读:232      评论:0      收藏:0      [点我收藏+]

标签:rtp   ntpdate   probe   lvm   python   3.1   ann   启动文件   war   

 

 

# 所有主机:基本系统配置

# 关闭Selinux/firewalld
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
 
# 关闭交换分区
swapoff -a
yes | cp /etc/fstab /etc/fstab_bak
cat /etc/fstab_bak |grep -v swap > /etc/fstab
 
# 设置网桥包经IPTables,core文件生成路径
echo """
vm.swappiness = 0
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
""" > /etc/sysctl.conf
sysctl -p
 
# 同步时间
yum install -y ntpdate
ntpdate -u ntp.api.bz
 
# 升级内核
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm ;yum --enablerepo=elrepo-kernel install kernel-ml-devel kernel-ml -y
 
# 检查默认内核版本是否大于4.14,否则请调整默认启动参数
grub2-editenv list
 
#重启以更换内核
reboot
 
# 确认内核版本后,开启IPVS
uname -a
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
ipvs_modules="ip_vs ip_vs_lc ip_vs_wlc ip_vs_rr ip_vs_wrr ip_vs_lblc ip_vs_lblcr ip_vs_dh ip_vs_sh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp nf_conntrack"
for kernel_module in \${ipvs_modules}; do
 /sbin/modinfo -F filename \${kernel_module} > /dev/null 2>&1
 if [ $? -eq 0 ]; then
 /sbin/modprobe \${kernel_module}
 fi
done
EOF
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep ip_vs

  

 

配置docker

# 所有主机:安装配置docker

# 安装docker
yum install -y yum-utils device-mapper-persistent-data lvm2
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
 
yum makecache fast
yum install -y docker-ce
 
# 编辑systemctl的Docker启动文件和配置文件
sed -i "13i ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT" /usr/lib/systemd/system/docker.service
mkdir -p /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
  "registry-mirrors": ["https://ftoplrr2.mirror.aliyuncs.com"]
}
EOF
 
# 启动docker
systemctl daemon-reload
systemctl enable docker
systemctl start docker

  

  

# 所有主机配置kubenetes仓库
cat > /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg enabled=1 EOF
#安装指定版本的kubeadm yum install -y kubelet-1.14.0-0.x86_64 kubectl-1.14.0-0.x86_64 kubeadm-1.14.0-0.x86_64 #忽略Swap echo ‘KUBELET_EXTRA_ARGS="--fail-swap-on=false"‘ > /etc/sysconfig/kubelet

  

使用python脚本下载镜像并改标签

#encoding=utf8
S_registry="mirrorgooglecontainers/"
D_registry="k8s.gcr.io/"
Z_registry="coredns/"


images_list = [
‘kube-apiserver:v1.14.0‘,
‘kube-controller-manager:v1.14.0‘,
‘kube-scheduler:v1.14.0‘,
‘kube-proxy:v1.14.0‘,
‘pause:3.1‘,
‘etcd:3.3.10‘,
‘coredns:1.3.1‘
]
import os

def PullImage(registry,images):
    print(‘一共%s个镜像‘%(len(images)))
    index=1
    for image in images:
        print(‘开始下载第%s个镜像%s‘%(index,image))
        if image == "coredns:1.3.1":
            cmd = "docker pull " + Z_registry + image
        else:
            cmd = "docker pull " + registry + image
        os.system(cmd)
        print(‘done!!!‘)
        index += 1

def DelImage(registry,images):
    for image in images:
        if image == "coredns:1.3.1":
            cmd = "docker rmi " + Z_registry + image
        else:
            cmd = "docker rmi " + registry+image
        os.system(cmd)
        print("已删除%s系列镜像"%(registry))


def TagImage(sregistry,dregistry,images):
    for image in images:
        if image == "coredns:1.3.1":
            cmd = "docker tag " + Z_registry+image + " "  + dregistry+image
        else:
            cmd = "docker tag " + sregistry+image + " " + dregistry+image
        os.system(cmd)
        print("done!!")


if __name__ == ‘__main__‘:
    PullImage(S_registry,images_list)
    TagImage(S_registry,D_registry,images_list)
    DelImage(S_registry,images_list)

  

# 初始化
kubeadm  init --kubernetes-version=v1.14.0 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=all

  

# 初始化完成后查看集群状态
[root@k8s001 ~]# kubectl get cs
NAME                 STATUS    MESSAGE             ERROR
scheduler            Healthy   ok                  
controller-manager   Healthy   ok                  
etcd-0               Healthy   {"health":"true"}   


# 查看各节点状态
[root@k8s001 ~]# kubectl get nodes
NAME                STATUS     ROLES    AGE   VERSION
k8s001.godufo.com   NotReady   master   58m   v1.14.0

  

  

 部署flaanel

https://github.com/coreos/flannel

技术图片

 

#自动获取在线的清单,并下载清单,部署启动flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

#***
kubectl get pods -n kube-system


#
kubectl get ns

  

node节点

#

  

  

kubeadm安装kubernetes集群

标签:rtp   ntpdate   probe   lvm   python   3.1   ann   启动文件   war   

原文地址:https://www.cnblogs.com/sonfer/p/10678734.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!