前言
容器技术:有效的将单个操作系统的资源划分到孤立的组中,技术核心就是通过对资源的限制和隔离把进程运行在一个沙盒中。 并且这个沙盒可以被打包成容器镜像(Image),任意地跨平台移植到另一台机器上可以直接运行,不需要任何的多余配置,其中 Docker 是容器技术的基础标准。
k8s 在 Docker 技术的基础上,为容器化的应用提供部署运行、资源调度、服务发现和动态伸缩等一系列完整功能,提高了大规模容器集群管理的便捷性。
实操动手搭建一套 K8s 集群环境,系统深入的学习容器技术,边搭建安装边记录实操整个过程,更好分享给各位有需要的同学们,希望同学们能少踩点坑,更快更高效的掌握容器相关技术,绝对不会错。
系统平台
操作系统: AlmaLinux 8.7 Linux 4.18.0-425.3.1.el8.x86_64
Kubernetes 集群资源规划
架构图
如下是收集其他网友的架构图,供参考学习。
下面开始动手安装,准备基础环境。
系统更新,所有主机上都需要执行。
安装所需的依赖包,所有主机上都需要执行。
所有主机上,都需安装配置 Docker ,添加阿里云 yum 源,并指定版本安装。
如下图所执行指令截图:
开始执行安装
# yum install --allowerasing docker-ce-3:20.10.21-3.el8
可以看到 Docker 容器已安装完成,也正常启动 Docker 服务。
如不能正常顺利的安装 Docker 容器,就需要到如下镜像站点,下载缺失的依赖包,再继续接着安装即可完成安装。
官方镜像链接: https://download.docker.com/linux/centos/
设置系统时区并同步时间服务器
[root@k8smaster scm]# rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
Retrieving http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:wlnmp-release-centos-2-1 ################################# [100%]
[root@gitlabcicd scm]# yum install ntpdate -y
gitlab_gitlab-ce 96 B/s | 862 B 00:08
gitlab_gitlab-ce-source 197 B/s | 862 B 00:04
Kubernetes 1.9 kB/s | 844 B 00:00
Kubernetes 37 kB/s | 4.2 kB 00:00
Importing GPG key 0x13EDEF05:
Userid : "Rapture Automatic Signing Key (cloud-rapture-signing-key-2022-03-07-08_01_01.pub)"
Fingerprint: A362 B822 F6DE DC65 2817 EA46 B53D C80D 13ED EF05
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Importing GPG key 0x307EA071:
Userid : "Rapture Automatic Signing Key (cloud-rapture-signing-key-2021-03-01-08_01_09.pub)"
Fingerprint: 7F92 E05B 3109 3BEF 5A3C 2D38 FEEA 9169 307E A071
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Importing GPG key 0xDC6315A3:
Userid : "Artifact Registry Repository Signer <[email protected]>"
Fingerprint: 35BA A0B3 3E9E B396 F59C A838 C0BA 5CE6 DC63 15A3
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Kubernetes 9.3 kB/s | 975 B 00:00
Importing GPG key 0x3E1BA8D5:
Userid : "Google Cloud Packages RPM Signing Key <[email protected]>"
Fingerprint: 3749 E1BA 95A8 6CE0 5454 6ED2 F09C 394C 3E1B A8D5
From : https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
Kubernetes 372 kB/s | 162 kB 00:00
wlnmp 2.1 MB/s | 2.2 MB 00:01
No match for argument: ntpdate
Error: Unable to find a match: ntpdate
[root@gitlabcicd scm]# dnf install wntp
Last metadata expiration check: 0:03:31 ago on Sun 11 Dec 2022 10:14:10 AM CST.
Dependencies resolved.
======================================================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================================================
Installing:
wntp x86_64 4.2.8p15-1.el8 wlnmp 1.9 M
Transaction Summary
======================================================================================================================================================================================
Install 1 Package
Total download size: 1.9 M
Installed size: 4.7 M
Is this ok [y/N]: y
Downloading Packages:
wntp-4.2.8p15-1.el8.x86_64.rpm 2.3 MB/s | 1.9 MB 00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 2.3 MB/s | 1.9 MB 00:00
wlnmp 10 kB/s | 1.7 kB 00:00
Importing GPG key 0xBCC6A00D:
Userid : "wlnmp (GPG-RPM-KEY) <[email protected]>"
Fingerprint: 5D5B 5609 0305 9039 D96E 717C 9F3B A65F BCC6 A00D
From : https://mirrors.wlnmp.com/centos/RPM-GPG-KEY-wlnmp
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Running scriptlet: wntp-4.2.8p15-1.el8.x86_64 1/1
Installing : wntp-4.2.8p15-1.el8.x86_64 1/1
Running scriptlet: wntp-4.2.8p15-1.el8.x86_64 1/1
Verifying : wntp-4.2.8p15-1.el8.x86_64 1/1
Installed:
wntp-4.2.8p15-1.el8.x86_64
Complete!
[root@k8smaster scm]#
[root@k8smaster scm]# ntpdate ntp1.aliyun.com
11 Dec 10:19:53 ntpdate[9498]: adjust time server 120.25.115.20 offset -0.384307 sec
[root@k8smaster scm]#
[root@k8smaster scm]# date
Sun Dec 11 10:19:57 CST 2022
[root@k8smaster scm]#
添加 kubernetes 阿里云 YUM 软件源
阿里云 yum 源
#################################################################################
cat <<EOF | sudo tee /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=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
阿里云镜像站
https://mirrors.aliyun.com/kubernetes/yum/repos/?spm=a2c6h.25603864.0.0.2613274fi1jVZy
执行安装
#
[root@k8smaster yum.repos.d]# yum install -y kubeadm kubectl kubelet
Kubernetes 1.5 kB/s | 844 B 00:00
Kubernetes 50 kB/s | 4.2 kB 00:00
Importing GPG key 0x13EDEF05:
Userid : "Rapture Automatic Signing Key (cloud-rapture-signing-key-2022-03-07-08_01_01.pub)"
Fingerprint: A362 B822 F6DE DC65 2817 EA46 B53D C80D 13ED EF05
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Importing GPG key 0x307EA071:
Userid : "Rapture Automatic Signing Key (cloud-rapture-signing-key-2021-03-01-08_01_09.pub)"
Fingerprint: 7F92 E05B 3109 3BEF 5A3C 2D38 FEEA 9169 307E A071
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Importing GPG key 0xDC6315A3:
Userid : "Artifact Registry Repository Signer <[email protected]>"
Fingerprint: 35BA A0B3 3E9E B396 F59C A838 C0BA 5CE6 DC63 15A3
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Kubernetes 10 kB/s | 975 B 00:00
Importing GPG key 0x3E1BA8D5:
Userid : "Google Cloud Packages RPM Signing Key <[email protected]>"
Fingerprint: 3749 E1BA 95A8 6CE0 5454 6ED2 F09C 394C 3E1B A8D5
From : https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
Kubernetes 284 kB/s | 162 kB 00:00
Dependencies resolved.
======================================================================================================================================================================================
Package Architecture Version Repository Size
======================================================================================================================================================================================
Installing:
kubeadm x86_64 1.26.0-0 kubernetes 10 M
kubectl x86_64 1.26.0-0 kubernetes 11 M
kubelet x86_64 1.26.0-0 kubernetes 22 M
Installing dependencies:
cri-tools x86_64 1.25.0-0 kubernetes 8.2 M
kubernetes-cni x86_64 1.1.1-0 kubernetes 15 M
Transaction Summary
======================================================================================================================================================================================
Install 5 Packages
Total download size: 66 M
Installed size: 290 M
Downloading Packages:
(1/5): e382ead81273ab8ebcddf14cc15bf977e44e1fd541a2cfda6ebe5741c255e59f-cri-tools-1.25.0-0.x86_64.rpm 997 kB/s | 8.2 MB 00:08
(2/5): da58cbf31a0337a968e5a06cfcc00eee420cc2df8930ea817ed2a4227bd81d48-kubeadm-1.26.0-0.x86_64.rpm 1.0 MB/s | 10 MB 00:10
(3/5): 23e112935127da08ffd1c32c392cbf62346305ee97ba6c5d070cda422945e4ff-kubectl-1.26.0-0.x86_64.rpm 987 kB/s | 11 MB 00:11
(4/5): 14083ac8b11792469524dae98ebb6905b3921923937d6d733b8abb58113082b7-kubernetes-cni-1.1.1-0.x86_64.rpm 845 kB/s | 15 MB 00:18
(5/5): 9be8590c2de60e249f40726e979a3a7a046320079bc41d330834de74f5399383-kubelet-1.26.0-0.x86_64.rpm 807 kB/s | 22 MB 00:27
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 1.8 MB/s | 66 MB 00:36
Kubernetes 45 kB/s | 4.2 kB 00:00
Importing GPG key 0x13EDEF05:
Userid : "Rapture Automatic Signing Key (cloud-rapture-signing-key-2022-03-07-08_01_01.pub)"
Fingerprint: A362 B822 F6DE DC65 2817 EA46 B53D C80D 13ED EF05
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Key imported successfully
Importing GPG key 0x307EA071:
Userid : "Rapture Automatic Signing Key (cloud-rapture-signing-key-2021-03-01-08_01_09.pub)"
Fingerprint: 7F92 E05B 3109 3BEF 5A3C 2D38 FEEA 9169 307E A071
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Key imported successfully
Importing GPG key 0xDC6315A3:
Userid : "Artifact Registry Repository Signer <[email protected]>"
Fingerprint: 35BA A0B3 3E9E B396 F59C A838 C0BA 5CE6 DC63 15A3
From : https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
Key imported successfully
Kubernetes 11 kB/s | 975 B 00:00
Importing GPG key 0x3E1BA8D5:
Userid : "Google Cloud Packages RPM Signing Key <[email protected]>"
Fingerprint: 3749 E1BA 95A8 6CE0 5454 6ED2 F09C 394C 3E1B A8D5
From : https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : kubernetes-cni-1.1.1-0.x86_64 1/5
Installing : kubelet-1.26.0-0.x86_64 2/5
Installing : kubectl-1.26.0-0.x86_64 3/5
Installing : cri-tools-1.25.0-0.x86_64 4/5
Installing : kubeadm-1.26.0-0.x86_64 5/5
Running scriptlet: kubeadm-1.26.0-0.x86_64 5/5
Verifying : cri-tools-1.25.0-0.x86_64 1/5
Verifying : kubeadm-1.26.0-0.x86_64 2/5
Verifying : kubectl-1.26.0-0.x86_64 3/5
Verifying : kubelet-1.26.0-0.x86_64 4/5
Verifying : kubernetes-cni-1.1.1-0.x86_64 5/5
Installed:
cri-tools-1.25.0-0.x86_64 kubeadm-1.26.0-0.x86_64 kubectl-1.26.0-0.x86_64 kubelet-1.26.0-0.x86_64 kubernetes-cni-1.1.1-0.x86_64
Complete!
[root@k8smaster yum.repos.d]# yum install -y kubeadm kubectl kubelet
Last metadata expiration check: 0:01:07 ago on Sun 11 Dec 2022 10:24:14 AM CST.
Package kubeadm-1.26.0-0.x86_64 is already installed.
Package kubectl-1.26.0-0.x86_64 is already installed.
Package kubelet-1.26.0-0.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@k8smaster yum.repos.d]#
导出集群初始化配置文件
标签:00,x86,kubernetes,AlmaLinux,64,yum,key,集群,K8s From: https://blog.51cto.com/wst021sh/5950822