k8部署搭建

2020-09-27 11:34:00
admin
原创
114
摘要:k8部署搭建

k8部署搭建

1、创建三个虚拟机

Vagrant.configure("2") do |config|
   (1..3).each do |i|
        config.vm.define "k8s-node#{i}" do |node|
            # 设置虚拟机的Box
            node.vm.box = "centos/7"

            # 设置虚拟机的主机名
            node.vm.hostname="k8s-node#{i}"

            # 设置虚拟机的IP
            node.vm.network "private_network", ip: "192.168.56.#{99+i}", netmask: "255.255.255.0"

            # 设置主机与虚拟机的共享目录
            # node.vm.synced_folder "~/Documents/vagrant/share", "/home/vagrant/share"

            # VirtaulBox相关配置
            node.vm.provider "virtualbox" do |v|
                # 设置虚拟机的名称
                v.name = "k8s-node#{i}"
                # 设置虚拟机的内存大小
                v.memory = 4096
                # 设置虚拟机的CPU个数
                v.cpus = 4
            end
        end
   end
end

新建Vagrantfile文件,然后在Vagrantfile文件的目录下面运行vagrant up

2、然后,vagrant ssh xxx进入到系统后

vi /etc/ssh/sshd_config
修改
PermitRootLogin yes 
PasswordAuthentication yes

三台虚拟机都修改,修改完成之后重启服务

service sshd  restart

3、修改网络

查看网络 

ip route show(查看默认网卡)

ip addr

先把虚拟机关闭,然后设置为natnetwork,然后重新生成一下mac地址

4、关闭防火墙

systemctl stop firewalld
systemctl disable firewalld
关闭selinux:
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0

关闭swap

swapoff -a #临时关闭
sed -ri 's/.*swap.*/#&/' /etc/fstab #永久关闭
free -g #验证,swap必须为0

5、添加主机名和ip对应关系

ip addr

vi /etc/hosts

10.0.2.4 k8s-node1
10.0.2.5 k8s-node2
10.0.2.15 k8s-node3

6、将桥接的IPV4流量传递到iptables的链:


cat > /etc/sysctl.d/k8s.conf <<EOF

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

EOF

7、然后应用规则:


sysctl --system


8、安装docker

首先卸载docker


 sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
安装docker -CE
sudo yum install -y yum-utils

sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

sudo yum -y install docker-ce docker-ce-cli containerd.io  

配置镜像加速


sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://ke9h1pt4.mirror.aliyuncs.com"]
}
EOF
启动和配置docker



sudo systemctl daemon-reload
sudo systemctl restart docker
systemctl enable docker


9、添加阿里云与yum源


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

10、安装kubeadm,kubelet和kubectl


yum install -y kubelet-1.17.3 kubeadm-1.17.3 kubectl-1.17.3

设置kubelet的开机启动

systemctl enable kubelet && systemctl start kubelet

11、查看kubelet的状态:


systemctl status kubelet


    发表评论
    评论通过审核之后才会显示。
    文章分类
    联系方式
    联系人: 郑州-小万
    电话: 13803993919
    Email: 1027060531@qq.com
    QQ: 1027060531
    网址: www.wanhejia.com