k8s入门之基础环境准备(一)
一、在虚拟机中安装Ubuntu20.04.4系统
1.下载Ubuntu20.04.4服务器版本系统
https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/20.04
2.在Vmware Workstation中安装该版本的系统(安装步骤略),注意虚拟机网络使用NAT模式
二、配置Ubuntu系统
1.设置root密码
sudo passwd
2.设置静态IP
(1)查看网卡设备号
ip a
(2)更改网络配置文件
使用以下命令编辑网络配置文件
nano /etc/netplan/00-installer-config.yaml
文件内容如下
network:
ethernets:
ens160: #配置的网卡的名称
addresses: [192.168.59.100/24] #配置的静态ip地址和掩码
dhcp4: no #关闭DHCP,如果需要打开DHCP则写yes
optional: true
gateway4: 192.168.59.2 #网关地址
nameservers:
addresses: [114.114.114.114,8.8.8.8] #DNS服务器地址,多个DNS服务器地址需要用英文逗号分隔开
version: 2
renderer: networkd #指定后端采用systemd-networkd或者Network Manager,可不填写则默认使用systemd-workd
(3)使配置生效
netplan apply
3.关闭防火墙
ufw disable
4.允许root用户ssh登录
(1)安装ssh server
apt install openssh-server
(2)修改ssh配置文件
vi /etc/ssh/sshd_config
#放开以下三行注释,并把PermitRootLogin的值改为yes,这样就允许root用户远程登录了
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
(3)重启ssh
service ssh restart
5.配置阿里源
(1)备份原始源
cp /etc/apt/source.list /etc/apt/source.list.backup
(2)修改源
vi /etc/apt/source.list
注释原有内容,把以下内容粘贴到文件中
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal universe
deb http://mirrors.aliyun.com/ubuntu/ focal-updates universe
deb http://mirrors.aliyun.com/ubuntu/ focal multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted
deb http://mirrors.aliyun.com/ubuntu/ focal-security universe
deb http://mirrors.aliyun.com/ubuntu/ focal-security multiverse
(3)更新源
apt update
apt upgrade
三、安装docker
1.直接根据官网文档就可以完美安装,安装的版本是20.10.14
https://docs.docker.com/engine/install/ubuntu
2.查看安装成功后的版本信息
docker version
Client: Docker Engine - Community
Version: 20.10.14
API version: 1.41
Go version: go1.16.15
Git commit: a224086
Built: Thu Mar 24 01:48:02 2022
linux/amd64 :
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.14
API version: 1.41 (minimum version 1.12)
Go version: go1.16.15
Git commit: 87a90dc
Built: Thu Mar 24 01:45:53 2022
linux/amd64 :
Experimental: false
containerd:
Version: 1.5.11
GitCommit: 3df54a852345ae127d1fa3092b95168e4a88e2f8
runc:
Version: 1.0.3
GitCommit: v1.0.3-0-gf46b6ba
:
Version: 0.19.0
GitCommit: de40ad0
3.设置镜像加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://ihujqq09.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
4.更改cgroup类型
docker默认的cgroup类型是cgroups
docker info|grep "Cgroup Driver"
Cgroup Driver: cgroupfs
由于新版本的k8s使用systemd作为其cgroup驱动,所以需要把docker的也改成systemd
cat << EOF > /etc/docker/daemon.json
{
"registry-mirrors": ["https://ihujqq09.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
然后重启docker
service docker restart
重新查看docker的cgroup驱动
docker info|grep "Cgroup Driver"
Cgroup Driver: systemd