Windows10下Hyper-V虚拟机安装kubernetes集群(二)配置虚拟机

相关文章
Windows10下Hyper-V虚拟机安装kubernetes集群(一)创建虚拟机
Windows10下Hyper-V虚拟机安装kubernetes集群(二)配置虚拟机
Windows10下Hyper-V虚拟机安装kubernetes集群(三)复制虚拟机
Windows10下Hyper-V虚拟机安装kubernetes集群(四)启动k8s

一、设置虚拟机网络

  • 1、 修改hosts文件

    vi /etc/hosts
    
    # 将下边内容加到文件的最后边
    192.168.137.10 k8s-master
    192.168.137.20 k8s-node01
    192.168.137.30 k8s-node02
    
  • 2、 修改配置文件

    vi /etc/sysconfig/network-scripts/ifcfg-eth0
    

    BOOTPROTO=dhcp 改为 BOOTPROTO=static
    在文件末尾追加以下内容:

    IPADDR=192.168.137.10
    NETMASK=255.255.255.0
    GATEWAY=192.168.137.1
    DNS1=192.168.137.1
    

    修改前
    Windows10下Hyper-V虚拟机安装kubernetes集群(二)配置虚拟机_第1张图片
    修改后
    Windows10下Hyper-V虚拟机安装kubernetes集群(二)配置虚拟机_第2张图片
    修改完成后保存并重启网络服务

    systemctl restart network.service
    

    重启完成后可以ping一下测试网络。

    这时已经可以进行ssh连接,但是一般会出现ssh连接超时问题,此时需要修改配置文件 /etc/ssh/sshd_config

    vi /etc/ssh/sshd_config
    

    #UseDNS yes 改为 UseDNS no ,即:将注释打开并将yes改为no。
    修改完之后重启服务:

    sudo service sshd restart
    
    • 如果sshd_config改完还是不可以,将ssh_config也同样改一下。

二、设置基本配置项

  • 1、 关闭防火墙
    systemctl stop firewalld && systemctl disable firewalld && iptables -F
    
  • 2、 关闭selinux
    sed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0
    
  • 3、 关闭swap分区
    sed -ri 's/.*swap.*/#&/' /etc/fstab
    
  • 4、 修改yum源
    • 4.1 备份本地的源文件
    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
    
    • 4.2 下载阿里云配置文件并重命名
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    

    对于下载慢的或者干脆下不了的,可以直接复制以下内容,自己在对应路径下新建文件并粘贴即可:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

三、安装docker

  • 1、安装依赖
    sudo yum install -y yum-utils device-mapper-persistent-data lvm2
    
  • 2、添加docker仓库
    sudo yum-config-manager --add-repo  https://download.docker.com/linux/centos/docker-ce.repo
    
  • 3、 安装docker
     sudo yum update -y && sudo yum install -y containerd.io-1.2.13 docker-ce-19.03.11 docker-ce-cli-19.03.11
    
  • 4、创建docker配置目录
    sudo mkdir /etc/docker
    
  • 5、 把docker的cgroup driver改为systemd
    cat >> /etc/docker/daemon.json <
    sudo mkdir -p /etc/systemd/system/docker.service.d
    
  • 6、 重启docker
    sudo systemctl daemon-reload
    sudo systemctl restart docker
    
  • 7、 设置开机启动
    sudo systemctl enable docker
    

三、安装k8s

所有节点都需要安装kubelet和kubeadm,master节点必须安装kubectl,woker节点kubectl可装可不装

  • 1、设置k8s源
    cat < /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
    
  • 2、安装kubelet、kubeadm、kubectl

    教程使用的是指定版本安装 1.20.14

    # 指定版本号安装
     yum install -y kubelet-1.20.14 kubectl-1.20.14 kubeadm-1.20.14
    
    # 最新版安装
    sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
    
  • 3、设置开机启动
    sudo systemctl enable --now kubelet
    
  • 4、查看本次安装结果
    yum list installed |grep kube
    
    在这里插入图片描述

至此,前期安装的准备工作基本完成

你可能感兴趣的:(Kubernetes,环境搭建,kubernetes,linux,centos,hyper-v)