k3s 安装

在 win10 hyperv 上 安装 centos7

启动centos7

k3s安装准备: github ip地址

不做这一步, k3s安装命令 “curl -sfL https://get.k3s.io | sh -” 中访问github 将无法访问

echo "
######github hosts begin
######20220218 updated

# GitHub520 Host Start
#140.82.114.25 alive.github.com
#140.82.113.26 live.github.com
#185.199.108.154 github.githubassets.com
#140.82.113.22 central.github.com
#185.199.108.133 desktop.githubusercontent.com
#185.199.108.153 assets-cdn.github.com
#185.199.108.133 camo.githubusercontent.com
#185.199.108.133 github.map.fastly.net
#199.232.69.194 github.global.ssl.fastly.net
#140.82.114.3 gist.github.com
#185.199.108.153 github.io
#140.82.114.3 github.com
192.0.66.2 github.blog
#140.82.113.5 api.github.com
#185.199.108.133 raw.githubusercontent.com
#185.199.108.133 user-images.githubusercontent.com
#185.199.108.133 favicons.githubusercontent.com
#185.199.108.133 avatars5.githubusercontent.com
#185.199.108.133 avatars4.githubusercontent.com
#185.199.108.133 avatars3.githubusercontent.com
#185.199.108.133 avatars2.githubusercontent.com
#185.199.108.133 avatars1.githubusercontent.com
#185.199.108.133 avatars0.githubusercontent.com
#185.199.108.133 avatars.githubusercontent.com
#140.82.112.10 codeload.github.com
#52.217.136.177 github-cloud.s3.amazonaws.com
#52.217.199.177 github-com.s3.amazonaws.com
#52.217.173.73 github-production-release-asset-2e65be.s3.amazonaws.com
#52.217.160.81 github-production-user-asset-6210df.s3.amazonaws.com
#52.217.227.161 github-production-repository-file-5c1aeb.s3.amazonaws.com
#185.199.108.153 githubstatus.com
#64.71.144.202 github.community
#23.100.27.125 github.dev
#185.199.108.133 media.githubusercontent.com
#185.199.108.133 cloud.githubusercontent.com
#185.199.108.133 objects.githubusercontent.com


# Update time: 2022-02-18T18:05:25+08:00
# Update url: https://raw.hellogithub.com/hosts
# Star me: https://github.com/521xueweihan/GitHub520
# GitHub520 Host End
######github hosts end
">/etc/hosts

k3s安装

命令

curl -sfL https://get.k3s.io | sh -

命令输出如下:

[root@localhost ~]# curl -sfL https://get.k3s.io | sh -
[INFO]  Finding release for channel stable
[INFO]  Using v1.22.7+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.22.7+k3s1/sha256sum-amd64.txt
[INFO]  Downloading binary https://github.com/k3s-io/k3s/releases/download/v1.22.7+k3s1/k3s
[INFO]  Verifying binary download
[INFO]  Installing k3s to /usr/local/bin/k3s
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.njupt.edu.cn
base                                                                                                                                                               | 3.6 kB  00:00:00
extras                                                                                                                                                             | 2.9 kB  00:00:00
updates                                                                                                                                                            | 2.9 kB  00:00:00
(1/4): base/7/x86_64/group_gz                                                                                                                                      | 153 kB  00:00:00
(2/4): extras/7/x86_64/primary_db                                                                                                                                  | 246 kB  00:00:00
(3/4): base/7/x86_64/primary_db                                                                                                                                    | 6.1 MB  00:00:01
(4/4): updates/7/x86_64/primary_db                                                                                                                                 |  14 MB  00:00:07
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be installed
--> Processing Dependency: python-kitchen for package: yum-utils-1.1.31-54.el7_8.noarch
--> Processing Dependency: libxml2-python for package: yum-utils-1.1.31-54.el7_8.noarch
--> Running transaction check
---> Package libxml2-python.x86_64 0:2.9.1-6.el7_9.6 will be installed
--> Processing Dependency: libxml2 = 2.9.1-6.el7_9.6 for package: libxml2-python-2.9.1-6.el7_9.6.x86_64
---> Package python-kitchen.noarch 0:1.1.1-5.el7 will be installed
--> Processing Dependency: python-chardet for package: python-kitchen-1.1.1-5.el7.noarch
--> Running transaction check
---> Package libxml2.x86_64 0:2.9.1-6.el7.5 will be updated
---> Package libxml2.x86_64 0:2.9.1-6.el7_9.6 will be an update
---> Package python-chardet.noarch 0:2.2.1-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================================
 Package                                         Arch                                    Version                                           Repository                                Size
==========================================================================================================================================================================================
Installing:
 yum-utils                                       noarch                                  1.1.31-54.el7_8                                   base                                     122 k
Installing for dependencies:
 libxml2-python                                  x86_64                                  2.9.1-6.el7_9.6                                   updates                                  247 k
 python-chardet                                  noarch                                  2.2.1-3.el7                                       base                                     227 k
 python-kitchen                                  noarch                                  1.1.1-5.el7                                       base                                     267 k
Updating for dependencies:
 libxml2                                         x86_64                                  2.9.1-6.el7_9.6                                   updates                                  668 k

Transaction Summary
==========================================================================================================================================================================================
Install  1 Package  (+3 Dependent packages)
Upgrade             ( 1 Dependent package)

Total download size: 1.5 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/base/packages/python-kitchen-1.1.1-5.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for python-kitchen-1.1.1-5.el7.noarch.rpm is not installed
(1/5): python-kitchen-1.1.1-5.el7.noarch.rpm                                                                                                                       | 267 kB  00:00:00
Public key for libxml2-python-2.9.1-6.el7_9.6.x86_64.rpm is not installed
(2/5): libxml2-python-2.9.1-6.el7_9.6.x86_64.rpm                                                                                                                   | 247 kB  00:00:00
(3/5): yum-utils-1.1.31-54.el7_8.noarch.rpm                                                                                                                        | 122 kB  00:00:00
(4/5): python-chardet-2.2.1-3.el7.noarch.rpm                                                                                                                       | 227 kB  00:00:00
(5/5): libxml2-2.9.1-6.el7_9.6.x86_64.rpm                                                                                                                          | 668 kB  00:00:00
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                     2.7 MB/s | 1.5 MB  00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libxml2-2.9.1-6.el7_9.6.x86_64                                                                                                                                         1/6
  Installing : libxml2-python-2.9.1-6.el7_9.6.x86_64                                                                                                                                  2/6
  Installing : python-chardet-2.2.1-3.el7.noarch                                                                                                                                      3/6
  Installing : python-kitchen-1.1.1-5.el7.noarch                                                                                                                                      4/6
  Installing : yum-utils-1.1.31-54.el7_8.noarch                                                                                                                                       5/6
  Cleanup    : libxml2-2.9.1-6.el7.5.x86_64                                                                                                                                           6/6
  Verifying  : python-chardet-2.2.1-3.el7.noarch                                                                                                                                      1/6
  Verifying  : libxml2-2.9.1-6.el7_9.6.x86_64                                                                                                                                         2/6
  Verifying  : libxml2-python-2.9.1-6.el7_9.6.x86_64                                                                                                                                  3/6
  Verifying  : python-kitchen-1.1.1-5.el7.noarch                                                                                                                                      4/6
  Verifying  : yum-utils-1.1.31-54.el7_8.noarch                                                                                                                                       5/6
  Verifying  : libxml2-2.9.1-6.el7.5.x86_64                                                                                                                                           6/6

Installed:
  yum-utils.noarch 0:1.1.31-54.el7_8

Dependency Installed:
  libxml2-python.x86_64 0:2.9.1-6.el7_9.6                         python-chardet.noarch 0:2.2.1-3.el7                         python-kitchen.noarch 0:1.1.1-5.el7

Dependency Updated:
  libxml2.x86_64 0:2.9.1-6.el7_9.6

Complete!
Loaded plugins: fastestmirror
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nju.edu.cn
 * extras: mirrors.nju.edu.cn
 * updates: mirrors.njupt.edu.cn
rancher-k3s-common-stable                                                                                                                                          | 2.9 kB  00:00:00
rancher-k3s-common-stable/primary_db                                                                                                                               | 3.4 kB  00:00:01
Resolving Dependencies
--> Running transaction check
---> Package k3s-selinux.noarch 0:1.1-1.el7 will be installed
--> Processing Dependency: container-selinux < 2:2.164.2 for package: k3s-selinux-1.1-1.el7.noarch
--> Processing Dependency: container-selinux >= 2:2.107-3 for package: k3s-selinux-1.1-1.el7.noarch
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
--> Processing Dependency: policycoreutils-python for package: 2:container-selinux-2.119.2-1.911c772.el7_8.noarch
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.5-34.el7 will be installed
--> Processing Dependency: setools-libs >= 3.3.8-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libsemanage-python >= 2.5-14 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libcgroup for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.5-34.el7.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.8.5-4.el7 will be installed
---> Package checkpolicy.x86_64 0:2.5-8.el7 will be installed
---> Package libcgroup.x86_64 0:0.41-21.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.5-14.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.8-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================================================================================================================
 Package                                        Arch                           Version                                            Repository                                         Size
==========================================================================================================================================================================================
Installing:
 k3s-selinux                                    noarch                         1.1-1.el7                                          rancher-k3s-common-stable                          16 k
Installing for dependencies:
 audit-libs-python                              x86_64                         2.8.5-4.el7                                        base                                               76 k
 checkpolicy                                    x86_64                         2.5-8.el7                                          base                                              295 k
 container-selinux                              noarch                         2:2.119.2-1.911c772.el7_8                          extras                                             40 k
 libcgroup                                      x86_64                         0.41-21.el7                                        base                                               66 k
 libsemanage-python                             x86_64                         2.5-14.el7                                         base                                              113 k
 policycoreutils-python                         x86_64                         2.5-34.el7                                         base                                              457 k
 python-IPy                                     noarch                         0.75-6.el7                                         base                                               32 k
 setools-libs                                   x86_64                         3.3.8-4.el7                                        base                                              620 k

Transaction Summary
==========================================================================================================================================================================================
Install  1 Package (+8 Dependent packages)

Total download size: 1.7 M
Installed size: 5.4 M
Downloading packages:
(1/9): container-selinux-2.119.2-1.911c772.el7_8.noarch.rpm                                                                                                        |  40 kB  00:00:00
(2/9): audit-libs-python-2.8.5-4.el7.x86_64.rpm                                                                                                                    |  76 kB  00:00:00
(3/9): libcgroup-0.41-21.el7.x86_64.rpm                                                                                                                            |  66 kB  00:00:00
(4/9): checkpolicy-2.5-8.el7.x86_64.rpm                                                                                                                            | 295 kB  00:00:00
(5/9): libsemanage-python-2.5-14.el7.x86_64.rpm                                                                                                                    | 113 kB  00:00:00
(6/9): python-IPy-0.75-6.el7.noarch.rpm                                                                                                                            |  32 kB  00:00:00
(7/9): policycoreutils-python-2.5-34.el7.x86_64.rpm                                                                                                                | 457 kB  00:00:00
(8/9): setools-libs-3.3.8-4.el7.x86_64.rpm                                                                                                                         | 620 kB  00:00:00
warning: /var/cache/yum/x86_64/7/rancher-k3s-common-stable/packages/k3s-selinux-1.1-1.el7.noarch.rpm: Header V4 RSA/SHA1 Signature, key ID e257814a: NOKEY2.9 kB/s | 1.7 MB  00:00:00 ETA
Public key for k3s-selinux-1.1-1.el7.noarch.rpm is not installed
(9/9): k3s-selinux-1.1-1.el7.noarch.rpm                                                                                                                            |  16 kB  00:00:05
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                     316 kB/s | 1.7 MB  00:00:05
Retrieving key from https://rpm.rancher.io/public.key
Importing GPG key 0xE257814A:
 Userid     : "Rancher (CI) <ci@rancher.com>"
 Fingerprint: c8cf f216 4551 26e9 b9c9 18be 925e a29a e257 814a
 From       : https://rpm.rancher.io/public.key
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                        1/9
  Installing : libcgroup-0.41-21.el7.x86_64                                                                                                                                           2/9
  Installing : audit-libs-python-2.8.5-4.el7.x86_64                                                                                                                                   3/9
  Installing : python-IPy-0.75-6.el7.noarch                                                                                                                                           4/9
  Installing : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                   5/9
  Installing : checkpolicy-2.5-8.el7.x86_64                                                                                                                                           6/9
  Installing : policycoreutils-python-2.5-34.el7.x86_64                                                                                                                               7/9
  Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                                                                     8/9
  Installing : k3s-selinux-1.1-1.el7.noarch                                                                                                                                           9/9
  Verifying  : checkpolicy-2.5-8.el7.x86_64                                                                                                                                           1/9
  Verifying  : k3s-selinux-1.1-1.el7.noarch                                                                                                                                           2/9
  Verifying  : libsemanage-python-2.5-14.el7.x86_64                                                                                                                                   3/9
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch                                                                                                                     4/9
  Verifying  : python-IPy-0.75-6.el7.noarch                                                                                                                                           5/9
  Verifying  : policycoreutils-python-2.5-34.el7.x86_64                                                                                                                               6/9
  Verifying  : audit-libs-python-2.8.5-4.el7.x86_64                                                                                                                                   7/9
  Verifying  : libcgroup-0.41-21.el7.x86_64                                                                                                                                           8/9
  Verifying  : setools-libs-3.3.8-4.el7.x86_64                                                                                                                                        9/9

Installed:
  k3s-selinux.noarch 0:1.1-1.el7

Dependency Installed:
  audit-libs-python.x86_64 0:2.8.5-4.el7     checkpolicy.x86_64 0:2.5-8.el7                 container-selinux.noarch 2:2.119.2-1.911c772.el7_8     libcgroup.x86_64 0:0.41-21.el7
  libsemanage-python.x86_64 0:2.5-14.el7     policycoreutils-python.x86_64 0:2.5-34.el7     python-IPy.noarch 0:0.75-6.el7                         setools-libs.x86_64 0:3.3.8-4.el7

Complete!
[INFO]  Creating /usr/local/bin/kubectl symlink to k3s
[INFO]  Creating /usr/local/bin/crictl symlink to k3s
[INFO]  Creating /usr/local/bin/ctr symlink to k3s
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink from /etc/systemd/system/multi-user.target.wants/k3s.service to /etc/systemd/system/k3s.service.
[INFO]  systemd: Starting k3s

安装完
在这里插入图片描述

k3s kubectl get node

在这里插入图片描述

172.26.43.214 为 “centos 7 @hyperv” ip地址

禁用防火墙

systemctl disable firewalld
systemctl stop firewalld

转发 "centos 7 @ hyperv " 其端口 到主机win10

在主机win10下运行

#netsh interface portproxy add v4tov4 listenport=外网端口 listenaddress=主IP connectaddress=私网IP connectport=私网IP端口

netsh interface portproxy add v4tov4 listenport=6443 listenaddress=127.0.0.1 connectaddress=172.26.43.214 connectport=6443

k3s dashboard 安装

kube-dashboard

GITHUB_URL=https://github.com/kubernetes/dashboard/releases
VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
k3s kubectl create -f https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐