Ubuntu 20.04 + containerd + calico搭建Kubernetes集群

一个master,一个node,配置2c4g

一、虚拟机配置

1、安装虚拟机

VMWare虚拟机中,安装两个Ubuntu20.04的虚拟机(略),linux内核需要大于4.15,网络适配器选择NAT


master01

node01

2、配置虚拟机固定IP,不要DHCP

以master01为例:

0、关闭防火墙

sudo apt-get install ufw
sudo ufw disable

a、查看默认IP其中192.168.11.135就是现在默认的IP地址

ylyang@ubuntu:~/Desktop$ ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:99:bb:71 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.11.135/24 brd 192.168.11.255 scope global dynamic noprefixroute ens33
       valid_lft 1277sec preferred_lft 1277sec
    inet6 fe80::9583:a81d:8d60:781/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

b、设置为固定IP

执行命令

ylyang@ubuntu:~/Desktop$ cd /etc/netplan/ && ls
01-network-manager-all.yaml  01-network-manager-all.yaml.bak
ylyang@ubuntu:/etc/netplan$ sudo apt-get install vim  #安装vim编辑器
ylyang@ubuntu:/etc/netplan$ sudo vim 01-network-manager-all.yaml

将配置文件修改为如下

# Let NetworkManager manage all devices on this system
network:
  ethernets:
    ens33:     #配置的网卡的名称
      addresses: [192.168.11.101/24]    #配置的静态ip地址和掩码
      dhcp4: no    #关闭DHCP,如果需要打开DHCP则写yes
      optional: true
      gateway4: 192.168.11.2   #网关地址
      nameservers:
         addresses: [8.8.8.8,8.8.4.4]    #DNS服务器地址,多个DNS服务器地址需要用英文逗号分隔开
  version: 2
  renderer: networkd    #指定后端采用systemd-networkd或者Network Manager,可不填写则默认使用systemd-workd

其中,gateway4是虚拟机网关地址,在VMWare中,编辑-虚拟网络编辑器,选择NAT模式的NAT设置中可以看到


image.png

address是要设置的静态IP,IP可设置的网段,在VMWare中,编辑-虚拟网络编辑器,选择NAT模式的NAT设置中可以看到


image.png

c、让配置生效:

ylyang@ubuntu:/etc/netplan$ sudo netplan apply
ylyang@ubuntu:/etc/netplan$ ip addr
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33:  mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:99:bb:71 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.11.101/24 brd 192.168.11.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::9583:a81d:8d60:781/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

可以看到,配置已经生效

3、ubuntu20.04开启ssh

sudo apt-get update
sudo apt-get install openssh-server

4、关闭swap

ylyang@ubuntu:~$ sudo vim /etc/fstab

注释掉文件里的swap

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#                
# / was on /dev/sda5 during installation
UUID=4afa31f7-7393-4784-834a-c1373556a508 /               ext4    errors=remount-ro 0       1
# /boot/efi was on /dev/sda1 during installation
UUID=956B-8E1A  /boot/efi       vfat    umask=0077      0       1
# /swapfile                                 none            swap    sw              0       0
/dev/fd0        /media/floppy0  auto    rw,user,noauto,exec,utf8 0       0

二、安装Kubeadm

参考官网安装教程:https://kubernetes.io/zh/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
安装到【下载 Google Cloud 公开签名秘钥:】,可以先用本机把文件下载下来,然后拷贝到对象目录(注意要重命名)
安装到【添加 Kubernetes apt 仓库:】,要换成国内源,比如中科大源:

echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] http://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list

1、修改主机名称

//1、查看当前主机的主机名称
hostname
//2、修改当前主机的主机名称
sudo hostnamectl set-hostname 主机名称

2、配置ip地址 与 主机名的映射关系

//1、编辑hosts文件
sudo vim /etc/hosts
//2、配置映射关系
192.168.198.145 k8s-master
192.168.198.146 k8s-node1
192.168.198.147 k8s-node2

3、关闭firewalld防火墙 和 SELinux

你可能感兴趣的:(Ubuntu 20.04 + containerd + calico搭建Kubernetes集群)