CI/CD—K8S 基本理解与部署

1 K8S 是什么

Kubernetes 是一款容器的编排调度工具,来源于 Google 开源的 Brog 系统。Kubernetes简称K8S,是用8代替8个字符 “ubernete” 而成的缩写,用于管理云平台中多个主机上的容器化的应用,Kubernetes 的目标是让部署容器化的应用简单并且高效,Kubernetes提供了应用部署,规划,更新,维护的一种机制。

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

集群中的各种角色
在这里插入图片描述
apiserver 所有服务访问的唯一入口,提供认证、授权、访问控制、API 注册和发现等机制
controller manager 负责维护集群的状态,比如副本期望数量、故障检测、自动扩展、滚动更新等
scheduler 负责资源的调度,按照预定的调度策略将 Pod 调度到相应的机器上
etcd 键值对数据库,保存了整个集群的状态
kubelet 负责维护容器的生命周期,同时也负责 Volume 和网络的管理
kube-proxy 负责为 Service 提供 cluster 内部的服务发现和负载均衡
Container runtime 负责镜像管理以及 Pod 和容器的真正运行

nginx 要调度到哪个工作节点呢?由scheduler监听API server发现有新的创建应用,通过API server 到 etcd 拿数据,然后 controller manager 确定哪个Node合适, 最后由API server指挥远程工作节点中的一个组件 Kubelet ,由 Kubelet 创建 pod:Kubelet 通过 cri-dockerd 操作 docker 创建 pod。
在这里插入图片描述
首先,将一个 K8s 比作一个集团,集团要做不同的项目,集群的各个角色就担任了不同的任务。

  • Node:就是各个负责工作的地方也就是工厂。
  • Kubelet:每一个工厂的负责人。
  • k-proxy:每一个工厂的门卫,当总部的人要来巡视工厂了,可以通过它来询问当前的项目是不是在这开展,不管有没有在它这开展它都能告诉领导该去哪里查看。
  • controller manager:决策者,决定项目由哪一个工厂来开展。
  • API server:秘书部,决策者的决策不会直接告诉工厂而是通过它来进行转达,同样地,工厂的情况也是通过它来转给决策者。
  • scheduler:调度者,调度项目的执行。
  • etcd:资料库,用于存放集团的资料。
    在这里插入图片描述
  • 每一个服务器中要有一个监工:kubelet,由它来负责监控整个服务器里面容器的监控状况
  • 所有的沟通都是通过秘书(api-server)
  • 所有的服务器都要装上运行时环境,可以是docker。
  • 可以通过命令的形式来进行部署

在这里插入图片描述

2 环境部署

1 ip规划:

vim /etc/hosts

192.168.21.20 kubernetes-master.inspur.com kubernetes-master
192.168.21.21 kubernetes-node1.inspur.com kubernetes-node1
192.168.21.22 kubernetes-node2.inspur.com kubernetes-node2
192.168.21.23 kubernetes-node3.inspur.com kubernetes-node3
192.168.21.24 kubernetes-register.inspur.com kubernetes-register

[root@inspur ~]# ssh-keygen -t rsa
[root@inspur ~]# ls .ssh/
id_rsa  id_rsa.pub[root@inspur ~]# for i in 20 21 22 23 24
> do
> ssh-copy-id root@192.168.21.$i
> done
[root@inspur ~]# for i in 20 21 22 23 24; do ssh root@192.168.21.$i "hostname"; done
inspur
inspur
inspur
inspur
inspur
[root@inspur ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.110.35.201 registrylibrary.com.cn
192.168.21.20 kubernetes-master.inspur.com kubernetes-master
192.168.21.21 kubernetes-node1.inspur.com kubernetes-node1
192.168.21.22 kubernetes-node2.inspur.com kubernetes-node2
192.168.21.23 kubernetes-node3.inspur.com kubernetes-node3
192.168.21.24 kubernetes-register.inspur.com kubernetes-register
[root@inspur ~]# hostnamectl set-hostname  kubernetes-master
[root@inspur ~]# exec /bin/bash
[root@kubernetes-master ~]# hostname
kubernetes-master
[root@kubernetes-master ~]# ssh root@192.168.21.21 "hostnamectl set-hostname  kubernetes-node1"
[root@kubernetes-master ~]# ssh root@192.168.21.22 "hostnamectl set-hostname  kubernetes-node2"
[root@kubernetes-master ~]# ssh root@192.168.21.23 "hostnamectl set-hostname  kubernetes-node3"
[root@kubernetes-master ~]# ssh root@192.168.21.24 "hostnamectl set-hostname  kubernetes-register"
[root@kubernetes-master ~]# for i in 20 21 22 23 24; do ssh root@192.168.21.$i "hostname"; done
kubernetes-master
kubernetes-node1
kubernetes-node2
kubernetes-node3
kubernetes-register

2 不重启电脑,禁用启用swap,立刻生效

# 禁用命令sudo swapoff -a
# 启用命令sudo swapon -a
# 查看交换分区的状态sudo free -m
[root@kubernetes-master ~]# vim  /etc/sysctl.d/k8s.conf
[root@kubernetes-master ~]# cat /etc/sysctl.d/k8s.conf
vm.swappiness=0

3 网络参数调整

配置iptables参数,使得流经网桥的流量也经过iptables/netfilter防火墙

[root@kubernetes-master ~]# vim /etc/sysctl.d/k8s.conf
[root@kubernetes-master ~]# cat /etc/sysctl.d/k8s.conf
vm.swappiness=0
net.bridge.bridge-nf-call-iptables  = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward                 = 1

配置生效

[root@kubernetes-master ~]# sudo modprobe overlay
[root@kubernetes-master ~]# sudo modprobe br_netfilter
[root@inspur ~]# sysctl -p /etc/sysctl.d/k8s.conf

4 容器环境配置

https://developer.aliyun.com/mirror/docker-ce?spm=a2c6h.13651102.0.0.3e221b11ixbXRM
dokcer的安装见之前的文章

systemctl enable docker

在这里插入图片描述
配置docker镜像加速器:

[root@kubernetes-master docker]# pwd
/etc/docker
[root@kubernetes-master docker]# cat daemon.json
{"registry-mirrors": ["https://4zmn196h.mirror.aliyuncs.com","http://74f21445.m.daocloud.io","https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://docker.mirrors.ustc.edu.cn"],"dns": ["8.8.8.8", "114.114.114.114"],"insecure-registries": ["kubernetes-register.inspur.com"],"exec-opts":[ "native.cgroupdriver=systemd"]
}
[root@kubernetes-master docker]#

5 cri环境操作

[root@kubernetes-master softs]# pwd
/data/softs
[root@kubernetes-master softs]# ll
total 0
[root@kubernetes-master softs]#

下载软件

[root@kubernetes-master softs]# wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.2/cri-dockerd-0.3.2.amd64.tgz

解压软件:

[root@kubernetes-master softs]# tar -zxvf cri-dockerd-0.3.2.amd64.tgz
[root@kubernetes-master system]# cd /usr/lib/systemd/system/
[root@kubernetes-master system]# chmod 777 cri-dockerd

在这里插入图片描述
配置启动文件:
/etc/systemd/system

[Unit]
Description=CRI Interface for Docker Application Container Engine
Documentation=https://docs.mirantis.com
After=network-online.target firewalld.service docker.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/local/bin/cri-dockerd --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9
--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin --container-runtime-endpoint=unix:///var/run/cri-dockerd.sock --cri-dockerd-root-directory=/var/lib/dockershim --docker-endpoint=unix:///var/run/docker.sock --cri-dockerd-root-directory=/var/lib/docker
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
Restart=always
StartLimitBurst=3
StartLimitInterval=60s 
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
TasksMax=infinity
Delegate=yes
KillMode=process
[Install]
WantedBy=multi-user.target

生成socket文件:
/etc/systemd/system

[Unit]
Description=CRI Docker socket for the API
PartOf=cri-docker.service
[Socket]
ListenStream=/var/run/cri-dockerd.sock
SocketMode=0660
SocketUser=root
SocketGroup=docker
[Install]
WantedBy=sockets.target
[root@kubernetes-master system]# cd /etc/systemd/system/

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
检查效果:

[root@kubernetes-master bin]# systemctl status cri-dockerd

在这里插入图片描述

 systemctl is-active cri-dockerd

设置服务开机自启动:

[root@kubernetes-master bin]# systemctl daemon-reload
[root@kubernetes-master bin]# systemctl enable cri-dockerd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/cri-dockerd.service to /etc/systemd/system/cri-dockerd.service.
[root@kubernetes-master bin]# systemctl restart cri-dockerd.service
[root@kubernetes-master bin]#

6 harbor仓库操作

下载软件:700M左右

wget https://github.com/goharbor/harbor/releases/download/v2.5.0/harbor-offline-installer-v2.5.0.tgz
curl -SL https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-linux-x86_64 -o /usr/local/bin/docker-composemv docker-compose-linux-x86_64 /usr/local/bin/docker-composechmod +x docker-composesudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
[root@kubernetes-register softs]# tar -zxvf docker-compose-linux-x86_64[root@kubernetes-register server]# pwd
/data/server
[root@kubernetes-register server]# ll
total 0
drwxr-xr-x. 2 root root 122 Aug  7 15:57 harbor
[root@kubernetes-register server]# cd harbor/
[root@kubernetes-register harbor]# ll
total 647720
-rw-r--r--. 1 root root      3361 Apr  7  2022 common.sh
-rw-r--r--. 1 root root 663227387 Apr  7  2022 harbor.v2.5.0.tar.gz
-rw-r--r--. 1 root root      9917 Apr  7  2022 harbor.yml.tmpl
-rwxr-xr-x. 1 root root      2500 Apr  7  2022 install.sh
-rw-r--r--. 1 root root     11347 Apr  7  2022 LICENSE
-rwxr-xr-x. 1 root root      1881 Apr  7  2022 prepare
[root@kubernetes-register harbor]#
[root@kubernetes-register harbor]# docker load < harbor.v2.5.0.tar.gz

在这里插入图片描述
修改配置文件:

[root@kubernetes-register harbor]# cp harbor.yml.tmpl harbor.yml
[root@kubernetes-register harbor]# vim harbor.yml
hostname: kubernetes-register.inspur.com

禁用https:

#https:# https port for harbor, default is 443# port: 443# The path of cert and key files for nginx#certificate: /your/certificate/path#private_key: /your/private/key/path
harbor_admin_password: 123456
data_volume: /data/server/harbor/data

生成配置文件:

[root@kubernetes-register harbor]# ./prepare
prepare base dir is set to /data/server/harbor
WARNING:root:WARNING: HTTP protocol is insecure. Harbor will deprecate http protocol in the future. Please make sure to upgrade to https
Generated configuration file: /config/portal/nginx.conf
Generated configuration file: /config/log/logrotate.conf
Generated configuration file: /config/log/rsyslog_docker.conf
Generated configuration file: /config/nginx/nginx.conf
Generated configuration file: /config/core/env
Generated configuration file: /config/core/app.conf
Generated configuration file: /config/registry/config.yml
Generated configuration file: /config/registryctl/env
Generated configuration file: /config/registryctl/config.yml
Generated configuration file: /config/db/env
Generated configuration file: /config/jobservice/env
Generated configuration file: /config/jobservice/config.yml
Generated and saved secret to file: /data/secret/keys/secretkey
Successfully called func: create_root_cert
Generated configuration file: /compose_location/docker-compose.yml
Clean up the input dir

启动安装:

[root@kubernetes-register harbor]# ./install.sh

在这里插入图片描述


[root@kubernetes-register harbor]# docker compose ps
NAME                IMAGE                                COMMAND                  SERVICE             CREATED             STATUS                             PORTS
harbor-core         goharbor/harbor-core:v2.5.0          "/harbor/entrypoint.…"   core                5 minutes ago       Up 31 seconds (healthy)
harbor-db           goharbor/harbor-db:v2.5.0            "/docker-entrypoint.…"   postgresql          5 minutes ago       Up 32 seconds (healthy)
harbor-jobservice   goharbor/harbor-jobservice:v2.5.0    "/harbor/entrypoint.…"   jobservice          5 minutes ago       Up 29 seconds (health: starting)
harbor-log          goharbor/harbor-log:v2.5.0           "/bin/sh -c /usr/loc…"   log                 5 minutes ago       Up 4 minutes (healthy)             127.0.0.1:1514->10514/tcp
harbor-portal       goharbor/harbor-portal:v2.5.0        "nginx -g 'daemon of…"   portal              5 minutes ago       Up 32 seconds (healthy)
nginx               goharbor/nginx-photon:v2.5.0         "nginx -g 'daemon of…"   proxy               5 minutes ago       Up 29 seconds (health: starting)   0.0.0.0:80->8080/tcp, :::80->8080/tcp
redis               goharbor/redis-photon:v2.5.0         "redis-server /etc/r…"   redis               5 minutes ago       Up 32 seconds (healthy)
registry            goharbor/registry-photon:v2.5.0      "/home/harbor/entryp…"   registry            5 minutes ago       Up 32 seconds (healthy)
registryctl         goharbor/harbor-registryctl:v2.5.0   "/home/harbor/start.…"   registryctl         5 minutes ago       Up 32 seconds (healthy)
[root@kubernetes-register harbor]#

有一个问题:
在这里插入图片描述
下线处理:

[root@kubernetes-register harbor]# docker-compose down
[+] Running 10/10✔ Container harbor-jobservice  Removed                                                                                                                                                      2.1s✔ Container nginx              Removed                                                                                                                                                      2.1s✔ Container registryctl        Removed                                                                                                                                                     10.4s✔ Container harbor-portal      Removed                                                                                                                                                      0.6s✔ Container harbor-core        Removed                                                                                                                                                      0.6s✔ Container registry           Removed                                                                                                                                                      0.4s✔ Container redis              Removed                                                                                                                                                      0.5s✔ Container harbor-db          Removed                                                                                                                                                      0.5s✔ Container harbor-log         Removed                                                                                                                                                     10.1s✔ Network harbor_harbor        Removed 

定制服务启动文件:

[root@kubernetes-register system]# pwd
/etc/systemd/system
[Unit]
Description=Harbor
After=docker.service systemd-networkd.service systemd-resolved.service
Requires=docker.service
Documentation=http://github.com/vmware/harbor
[Service]
Type=simple
Restart=on-failure
RestartSec=5
ExecStart=/usr/bin/docker-compose --file /data/server/harbor/docker-compose.yml upExecStop=/usr/bin/docker-compose --file /data/server/harbor/docker-compose.yml down
[Install]
WantedBy=multi-user.target

在这里插入图片描述

[root@kubernetes-register ~]# cd /data/server/harbor/
[root@kubernetes-register harbor]# docker-compose ps
NAME                IMAGE                                COMMAND                  SERVICE             CREATED             STATUS                   PORTS
harbor-core         goharbor/harbor-core:v2.5.0          "/harbor/entrypoint.…"   core                2 minutes ago       Up 2 minutes (healthy)
harbor-db           goharbor/harbor-db:v2.5.0            "/docker-entrypoint.…"   postgresql          2 minutes ago       Up 2 minutes (healthy)
harbor-jobservice   goharbor/harbor-jobservice:v2.5.0    "/harbor/entrypoint.…"   jobservice          2 minutes ago       Up 2 minutes (healthy)
harbor-log          goharbor/harbor-log:v2.5.0           "/bin/sh -c /usr/loc…"   log                 2 minutes ago       Up 2 minutes (healthy)   127.0.0.1:1514->10514/tcp
harbor-portal       goharbor/harbor-portal:v2.5.0        "nginx -g 'daemon of…"   portal              2 minutes ago       Up 2 minutes (healthy)
nginx               goharbor/nginx-photon:v2.5.0         "nginx -g 'daemon of…"   proxy               2 minutes ago       Up 2 minutes (healthy)   0.0.0.0:80->8080/tcp, :::80->8080/tcp
redis               goharbor/redis-photon:v2.5.0         "redis-server /etc/r…"   redis               2 minutes ago       Up 2 minutes (healthy)
registry            goharbor/registry-photon:v2.5.0      "/home/harbor/entryp…"   registry            2 minutes ago       Up 2 minutes (healthy)
registryctl         goharbor/harbor-registryctl:v2.5.0   "/home/harbor/start.…"   registryctl         2 minutes ago       Up 2 minutes (healthy)
[root@kubernetes-register harbor]#

创建一个用户:

Inspur930312043@qq.com

在这里插入图片描述
用自己的账号登录并创建一个项目:
在这里插入图片描述
在这里插入图片描述

[root@kubernetes-master ~]# docker tag  nginx:latest kubernetes-register.inspur.com/inspur/nginx:2.22.01[root@kubernetes-master ~]# docker tag  tomcat:latest kubernetes-register.inspur.com/inspur/tomcat:11.1.01

上传镜像到私有仓库:

[root@kubernetes-master ~]# docker images
REPOSITORY                                     TAG       IMAGE ID       CREATED         SIZE
nginx                                          latest    605c77e624dd   19 months ago   141MB
kubernetes-register.inspur.com/inspur/nginx    2.22.01   605c77e624dd   19 months ago   141MB
tomcat                                         latest    fb5657adc892   19 months ago   680MB
kubernetes-register.inspur.com/inspur/tomcat   11.1.01   fb5657adc892   19 months ago   680MB
[root@kubernetes-master ~]# docker login kubernetes-register.inspur.com
Username: inspur
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-storeLogin Succeeded
[root@kubernetes-master ~]# docker push kubernetes-register.inspur.com/inspur/tomcat:11.1.01
The push refers to repository [kubernetes-register.inspur.com/inspur/tomcat]
3e2ed6847c7a: Pushed
bd2befca2f7e: Pushed
59c516e5b6fa: Pushed
3bb5258f46d2: Pushed
832e177bb500: Pushed
f9e18e59a565: Pushed
26a504e63be4: Pushed
8bf42db0de72: Pushed
31892cc314cb: Pushed
11936051f93b: Pushed
11.1.01: digest: sha256:e6d65986e3b0320bebd85733be1195179dbce481201a6b3c1ed27510cfa18351 size: 2422
[root@kubernetes-master ~]# docker push kubernetes-register.inspur.com/inspur/nginx:2.22.01
The push refers to repository [kubernetes-register.inspur.com/inspur/nginx]
d874fd2bc83b: Pushed
32ce5f6a5106: Pushed
f1db227348d0: Pushed
b8d6e692a25e: Pushed
e379e8aedd4d: Pushed
2edcec3590a4: Pushed
2.22.01: digest: sha256:ee89b00528ff4f02f2405e4ee221743ebc3f8e8dd0bfd5c4c20a2fa2aaa7ede3 size: 1570
[root@kubernetes-master ~]#

拉取镜像:

[root@kubernetes-register harbor]# docker pull kubernetes-register.inspur.com/inspur/tomcat@sha256:e6d65986e3b0320bebd85733be1195179dbce481201a6b3c1ed27510cfa18351
kubernetes-register.inspur.com/inspur/tomcat@sha256:e6d65986e3b0320bebd85733be1195179dbce481201a6b3c1ed27510cfa18351: Pulling from inspur/tomcat
Digest: sha256:e6d65986e3b0320bebd85733be1195179dbce481201a6b3c1ed27510cfa18351
Status: Image is up to date for kubernetes-register.inspur.com/inspur/tomcat@sha256:e6d65986e3b0320bebd85733be1195179dbce481201a6b3c1ed27510cfa18351
kubernetes-register.inspur.com/inspur/tomcat@sha256:e6d65986e3b0320bebd85733be1195179dbce481201a6b3c1ed27510cfa18351
[root@kubernetes-register harbor]# docker images
REPOSITORY                                     TAG       IMAGE ID       CREATED         SIZE
goharbor/harbor-exporter                       v2.5.0    36396f138dfb   16 months ago   86.7MB
goharbor/chartmuseum-photon                    v2.5.0    eaedcf1f700b   16 months ago   225MB
goharbor/redis-photon                          v2.5.0    1e00fcc9ae63   16 months ago   156MB
goharbor/trivy-adapter-photon                  v2.5.0    4e24a6327c97   16 months ago   164MB
goharbor/notary-server-photon                  v2.5.0    6d5fe726af7f   16 months ago   112MB
goharbor/notary-signer-photon                  v2.5.0    932eed8b6e8d   16 months ago   109MB
goharbor/harbor-registryctl                    v2.5.0    90ef6b10ab31   16 months ago   136MB
goharbor/registry-photon                       v2.5.0    30e130148067   16 months ago   77.5MB
goharbor/nginx-photon                          v2.5.0    5041274b8b8a   16 months ago   44MB
goharbor/harbor-log                            v2.5.0    89fd73f9714d   16 months ago   160MB
goharbor/harbor-jobservice                     v2.5.0    1d097e877be4   16 months ago   226MB
goharbor/harbor-core                           v2.5.0    42a54bc05b02   16 months ago   202MB
goharbor/harbor-portal                         v2.5.0    c206e936f4f9   16 months ago   52.3MB
goharbor/harbor-db                             v2.5.0    d40a1ae87646   16 months ago   223MB
goharbor/prepare                               v2.5.0    36539574668f   16 months ago   268MB
tomcat                                         latest    fb5657adc892   19 months ago   680MB
kubernetes-register.inspur.com/inspur/tomcat   11.1.01   fb5657adc892   19 months ago   680MB

7 K8s集群初始化

在这里插入图片描述
配置阿里云镜像:

cat <<EOF > /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
setenforce 0

软件安装:

yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet

在这里插入图片描述

[root@kubernetes-master ~]# kubeadm version
kubeadm version: &version.Info{Major:"1", Minor:"27", GitVersion:"v1.27.4", GitCommit:"fa3d7990104d7c1f16943a67f11b154b71f6a132", GitTreeState:"clean", BuildDate:"2023-07-19T12:19:40Z", GoVersion:"go1.20.6", Compiler:"gc", Platform:"linux/amd64"}
[root@kubernetes-master ~]# kubeadm config images list
registry.k8s.io/kube-apiserver:v1.27.4
registry.k8s.io/kube-controller-manager:v1.27.4
registry.k8s.io/kube-scheduler:v1.27.4
registry.k8s.io/kube-proxy:v1.27.4
registry.k8s.io/pause:3.9
registry.k8s.io/etcd:3.5.7-0
registry.k8s.io/coredns/coredns:v1.10.1
[root@kubernetes-master ~]# kubeadm config list | awk -F '/' '{print $NF}'
invalid subcommand "list"
See 'kubeadm config -h' for help and examples
[root@kubernetes-master ~]# kubeadm config images list | awk -F '/' '{print $NF}'
kube-apiserver:v1.27.4
kube-controller-manager:v1.27.4
kube-scheduler:v1.27.4
kube-proxy:v1.27.4
pause:3.9
etcd:3.5.7-0
coredns:v1.10.1
images=$(kubeadm config images list --kubernetes-version=1.27.4 | awk -F "/" '{print $NF}')
for i in ${images}
do
docker pull registry.aliyuncs.com/google_containers/$i
docker tag registry.aliyuncs.com/google_containers/$i kubernetes-register.inspur.com/google_containers/$i
docker push kubernetes-register.inspur.com/google_containers/$i
docker rmi registry.aliyuncs.com/google_containers/$i
done

环境初始化:
在这里插入图片描述

[root@kubernetes-master ~]# kubeadm init --kubernetes-version=1.27.4 --apiserver-advertise-address=192.168.21.20 --image-repository=kubernetes-register.inspur.com/google_containers --pod-network-cidr="172.17.1.0/16" --service-cidr="10.96.0.0/12" --ignore-preflight-errors=Swap --cri-socket=unix:///var/run/cri-dockerd.sock

分别在node1 node2 node3 执行

kubeadm join 192.168.21.20:6443 --token ymlg0w.xkl1z4pr7dwg39yr --discovery-token-ca-cert-hash sha256:ec15cba4c2e6bf2291ff1217f4e9bd41ee28aa02139e6fc86e614a5b8c6f4b96 --cri-socket=unix:///var/run/cri-dockerd.sock

但是现在还是有一个问题:
在这里插入图片描述
运行如下命令:

[root@kubernetes-master ~]#   mkdir -p $HOME/.kube
[root@kubernetes-master ~]#   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@kubernetes-master ~]#   sudo chown $(id -u):$(id -g) $HOME/.kube/config
[root@kubernetes-master ~]# kubectl get nodes
NAME                STATUS     ROLES           AGE     VERSION
kubernetes-master   NotReady   control-plane   5m8s    v1.27.4
kubernetes-node1    NotReady   <none>          2m56s   v1.27.4
kubernetes-node2    NotReady   <none>          2m46s   v1.27.4
kubernetes-node3    NotReady   <none>          2m44s   v1.27.4
[root@kubernetes-master ~]#

命令补全:

source <(kubectl completion bash)
source <(kubeadm completion bash)
[root@kubernetes-master ~]# vim .bashrc
[root@kubernetes-master ~]# cat .bashrc
# .bashrc# User specific aliases and functionsalias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fi
source <(kubectl completion bash)
source <(kubeadm completion bash)
[root@kubernetes-master ~]# source .bashrc
[root@kubernetes-master ~]# kubectl get n
namespaces                         networkpolicies.networking.k8s.io  nodes
[root@kubernetes-master ~]# kubectl get n
namespaces                         networkpolicies.networking.k8s.io  nodes
[root@kubernetes-master ~]# kubectl get n

网络配置:

 https://kubernetes.io/docs/concepts/cluster-administration/addons/

[root@kubernetes-master flannel]# pwd
/data/kubernetes/network/flannel
[root@kubernetes-master flannel]# ll
total 16
-rw-r--r--. 1 root root 4459 Aug  8 09:42 kube-flannel.yml
-rw-r--r--. 1 root root 4459 Aug  8 09:42 kube-flannel.ymlBK
[root@kubernetes-master flannel]#

在这里插入图片描述
需要下载一下三个镜像文件:

[root@kubernetes-master flannel]# grep image: kube-flannel.ymlimage: docker.io/flannel/flannel:v0.22.1image: docker.io/flannel/flannel-cni-plugin:v1.2.0image: docker.io/flannel/flannel:v0.22.1
[root@kubernetes-master flannel]# docker tag flannel/flannel:v0.22.1 kubernetes-register.inspur.com/inspur/flannel/flannel:v0.22.1
[root@kubernetes-master flannel]# docker tag flannel/flannel-cni-plugin:v1.2.0 kubernetes-register.inspur.com/inspur/flannel/flannel-cni-plugin:v1.2.0

推送到远程私有仓库:

[root@kubernetes-master flannel]# docker push  kubernetes-register.inspur.com/inspur/flannel/flannel:v0.22.1
The push refers to repository [kubernetes-register.inspur.com/inspur/flannel/flannel]
c120dc707e2b: Pushed
92e727b491c6: Pushed
23d8410e16ff: Pushed
9726974aad9b: Pushed
117eda391951: Pushed
40afc0fa6094: Pushed
d8ddfa4843bd: Pushed
f1417ff83b31: Pushed
v0.22.1: digest: sha256:02cb1205742b0d087f89d654cbe5fa8f815e97e4e5cc86c7f39bd7933d1a04cb size: 1996
[root@kubernetes-master flannel]# docker push kubernetes-register.inspur.com/inspur/flannel/flannel-cni-plugin:v1.2.0
The push refers to repository [kubernetes-register.inspur.com/inspur/flannel/flannel-cni-plugin]
9332f71f5f3d: Pushed
7df5bd7bd262: Pushed
v1.2.0: digest: sha256:2180bb74f60bea56da2e9be2004271baa6dccc0960b7aeaf43a97fc4de9b1ae0 size: 739
[root@kubernetes-master flannel]#

修改yml文件:
在这里插入图片描述

[root@kubernetes-master flannel]# kubectl apply -f kube-flannel.yml
namespace/kube-flannel created
serviceaccount/flannel created
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created
[root@kubernetes-master flannel]#

查看namespace:

[root@kubernetes-master flannel]# kubectl get ns
NAME              STATUS   AGE
default           Active   34m
kube-flannel      Active   53s
kube-node-lease   Active   34m
kube-public       Active   34m
kube-system       Active   34m
[root@kubernetes-master flannel]#
[root@kubernetes-master flannel]# kubectl get pod -n kube-flannel
NAME                    READY   STATUS             RESTARTS      AGE
kube-flannel-ds-mdpkb   0/1     CrashLoopBackOff   4 (29s ago)   2m33s
kube-flannel-ds-pg4x6   0/1     CrashLoopBackOff   4 (44s ago)   2m33s
kube-flannel-ds-vjw5j   0/1     CrashLoopBackOff   4 (40s ago)   2m33s
kube-flannel-ds-wzwx9   0/1     CrashLoopBackOff   4 (41s ago)   2m33s
[root@kubernetes-master flannel]# kubectl get nodes
NAME                STATUS   ROLES           AGE   VERSION
kubernetes-master   Ready    control-plane   36m   v1.27.4
kubernetes-node1    Ready    <none>          34m   v1.27.4
kubernetes-node2    Ready    <none>          34m   v1.27.4
kubernetes-node3    Ready    <none>          34m   v1.27.4
[root@kubernetes-master flannel]#

在这里插入图片描述

[root@kubernetes-master flannel]# systemctl is-active kubelet cri-dockerd docker
active
active
active
[root@kubernetes-master flannel]# systemctl enable  kubelet cri-dockerd docker

8 应用部署

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/89449.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

MongoDB 更新文档(更新数组对象中的元素)

之前我们介绍了如何更新文档&#xff0c;并简单的介绍了更新文档时可以使用选项进行指定当更新内容不存在时&#xff0c;可以进行新增文档。具体可以参考&#xff1a; MongoDB 更新文档(更新一条文档)https://blog.csdn.net/m1729339749/article/details/129983304 最近遇到了…

【从零学习python 】19. 循环遍历列表和列表嵌套的应用

文章目录 列表的循环遍历1. 使用while循环2. 使用for循环3. 交换2个变量的值1. 列表嵌套2. 应用 进阶案例 列表的循环遍历 1. 使用while循环 为了更有效率的输出列表的每个数据&#xff0c;可以使用循环来完成 namesList [xiaoWang,xiaoZhang,xiaoHua] length len(namesLi…

OSCS开源安全周报第 55 期:JeecgBoot 远程代码执行漏洞

本周安全态势综述 OSCS 社区共收录安全漏洞 11 个&#xff0c;公开漏洞值得关注的是 JeecgBoot 远程代码执行漏洞、企业微信私有化后台API未授权访问漏洞、WPS Office 存在代码执行漏洞(MPS-3pcb-l4mv)、Microsoft Exchange Server 远程代码执行漏洞(CVE-2023-38182)、Smartbi…

【深度学习】【风格迁移】Visual Concept Translator,一般图像到图像的翻译与一次性图像引导,论文

General Image-to-Image Translation with One-Shot Image Guidance 论文&#xff1a;https://arxiv.org/abs/2307.14352 代码&#xff1a;https://github.com/crystalneuro/visual-concept-translator 文章目录 Abstract1. Introduction2. 相关工作2.1 图像到图像转换2.2. Di…

【信号生成器】从 Excel 数据文件创建 Simulink 信号生成器块研究(Simulink)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

Java课题笔记~ Spring 集成 MyBatis

Spring 集成 MyBatis 将 MyBatis 与 Spring 进行整合&#xff0c;主要解决的问题就是将 SqlSessionFactory 对象交由 Spring 来管理。所以该整合&#xff0c;只需要将 SqlSessionFactory 的对象生成器SqlSessionFactoryBean 注册在 Spring 容器中&#xff0c;再将其注入给 Dao…

DTC服务(0x14 0x19 0x85)

DTC相关的服务有ReadDTCInformation (19) service&#xff0c;ControlDTCSetting (85) service和ReadDTCInformation (19) service ReadDTCInformation (19) service 该服务允许客户端从车辆内任意一台服务器或一组服务器中读取驻留在服务器中的诊断故障代码( DTC )信息的状态…

Java智慧工地APP源码带AI识别

智慧工地为建筑全生命周期赋能&#xff0c;用创新的可视化与智能化方法&#xff0c;降低成本&#xff0c;创造价值。 一、智慧工地APP概述 智慧工地”立足于互联网&#xff0c;采用云计算&#xff0c;大数据和物联网等技术手段&#xff0c;针对当前建筑行业的特点&#xff0c;…

ubuntu 安装 python

ubuntu 安装 python 初环境与设备查询是否安装安装python 本篇文章将介绍ubuntu 安装 python 初 希望能写一些简单的教程和案例分享给需要的人 环境与设备 系统&#xff1a;ubuntu 查询是否安装 因为系统也许会自带一个python&#xff0c;所以验证一下&#xff0c;如果自…

2023年国赛数学建模思路 - 案例:FPTree-频繁模式树算法

文章目录 算法介绍FP树表示法构建FP树实现代码 建模资料 ## 赛题思路 &#xff08;赛题出来以后第一时间在CSDN分享&#xff09; https://blog.csdn.net/dc_sinor?typeblog 算法介绍 FP-Tree算法全称是FrequentPattern Tree算法&#xff0c;就是频繁模式树算法&#xff0c…

2021年03月 C/C++(二级)真题解析#中国电子学会#全国青少年软件编程等级考试

第1题&#xff1a;石头剪刀布 石头剪刀布是常见的猜拳游戏。石头胜剪刀&#xff0c;剪刀胜布&#xff0c;布胜石头。如果两个人出拳一样&#xff0c;则不分胜负。 一天&#xff0c;小A和小B正好在玩石头剪刀布。已知他们的出拳都是有周期性规律的&#xff0c;比如&#xff1a;“…

拒绝摆烂!C语言练习打卡第一天

&#x1f525;博客主页&#xff1a;小王又困了 &#x1f4da;系列专栏&#xff1a;每日一练 &#x1f31f;人之为学&#xff0c;不日近则日退 ❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ &#x1f5d2;️前言&#xff1a; 在前面我们学习完C语言的所以知识&#xff0c;当…

Python爬虫 爬取图片

在我们日常上网浏览网页的时候&#xff0c;经常会看到一些好看的图片&#xff0c;我们就希望把这些图片保存下载&#xff0c;或者用户用来做桌面壁纸&#xff0c;或者用来做设计的素材。 我们最常规的做法就是通过鼠标右键&#xff0c;选择另存为。但有些图片鼠标右键的时候并没…

大数据分析案例-基于KMeans和DBSCAN算法对汽车行业客户进行聚类分群

&#x1f935;‍♂️ 个人主页&#xff1a;艾派森的个人主页 ✍&#x1f3fb;作者简介&#xff1a;Python学习者 &#x1f40b; 希望大家多多支持&#xff0c;我们一起进步&#xff01;&#x1f604; 如果文章对你有帮助的话&#xff0c; 欢迎评论 &#x1f4ac;点赞&#x1f4…

Wireshark有线网卡抓包报错The capture session could not be initiated on capture device

最近在使用Wireshark进行抓包排错时&#xff0c;选择网卡后提示报错&#xff0c;在此之前从未出现过&#xff0c;报错内容如下&#xff1a; 提示内容是The capture session could not be initiated on capture device&#xff0c;无法在捕获设备上启动捕获会话要求操作是Please…

Python—行命令搭建HTTP服务器并外网访问本地SQL Server数据库【无公网IP内网穿透】

在强者的眼中&#xff0c;没有最好&#xff0c;只有更好。我们是移动开发领域的优质创作者&#xff0c;同时也是阿里云专家博主。 ✨ 关注我们的主页&#xff0c;探索iOS开发的无限可能&#xff01; &#x1f525;我们与您分享最新的技术洞察和实战经验&#xff0c;助您在移动…

Java课题笔记~ JSTL

使用EL表达式已经实现了页面输出显示的优化&#xff0c;为什么还需要使用JSTL呢&#xff1f; 这是因为使用EL表达式无法实现逻辑处理&#xff0c;如循环、条件判断等&#xff0c;因此还需要与Java代码混合使用&#xff0c;而JSTL则可以实现逻辑控制&#xff0c;从而进一步优化…

css实现文字首行缩进的效果

<div class"content"><p>站在徐汇滨江西岸智塔45楼&#xff0c;波光粼粼的黄浦江一览无余。近处&#xff0c;是由龙华机场储油罐改造而来的油罐艺术中心和阿里巴巴上海总部办公处。远处&#xff0c;历史悠久的龙华塔挺拔秀丽&#xff0c;总投资逾600亿元…

提高 After Effects 效率的 40 个最佳快捷键

After Effects 是运动图形和视觉效果的强大工具&#xff0c;但它也可能让人不知所措。拥有如此多的特性和功能&#xff0c;很容易让人迷失在软件中。但是&#xff0c;有一种方法可以简化您的工作流程并提高工作效率 - 使用键盘快捷键。 After Effects素材文件巨大、占用电脑内…

腾讯云服务器镜像操作系统大全_Linux_Windows清单

腾讯云CVM服务器的公共镜像是由腾讯云官方提供的镜像&#xff0c;公共镜像包含基础操作系统和腾讯云提供的初始化组件&#xff0c;公共镜像分为Windows和Linux两大类操作系统&#xff0c;如TencentOS Server、Windows Server、OpenCloudOS、CentOS Stream、CentOS、Ubuntu、Deb…