【Kubernetes】第十七篇 - ECS 服务停机和环境修复
创始人
2024-05-28 18:12:51
0

一,前言

上一篇,介绍了 Secret 镜像的使用;

三台服务每天大概 15 块钱的支出,用一个月也是不少钱;

闲时可以停掉,这样每天只有 4 块钱支出,剩下一大笔;

ECS 服务停机后公网 IP 会变化,所以使用到公网 IP 的地方都需要重新配置,恢复环境;

本篇,介绍 ECS 停机后重启的环境修复;

备注:只涉及到目前未知的配置,后续章节可能会新增其他配置项,全部完成之后再补充一篇熊进行说明;


二,ci-service 服务器重启问题

ci-service 服务器停机后重启:

1,导致公网 IP 变化:39.105.212.14 -> 47.94.92.122;

2,服务器重启后:docker 镜像仓库无法访问;

三,环境修复

1,启动 docker 私有镜像仓库

[root@iZ2ze7rkgit9zoa18pxu73Z ~]# cd /usr/local/nexus-3.29.0-02/bin/
[root@iZ2ze7rkgit9zoa18pxu73Z bin]# ./nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user.  This is NOT recommended!
WARNING: ************************************************************
Starting nexus

http://47.94.92.122:8081/ 可以正常访问私有镜像仓库,登录后查看镜像正常

2,更新公网 ip

ci-service 服务器公网 IP 变化:39.105.212.14 -> 47.94.92.122;

需要更新所有使用私有库镜像的 yaml 配置文件:

1,ci-service 的 jenkins 构建脚本更新,推送镜像到私有仓库部分

修改前脚本

// 更新前
#!/bin/sh -l
npm install --registry=https://registry.npm.taobao.org
npm run build
time=$(date "+%Y%m%d%H%M%s")
docker build -t 39.105.212.14:8082/vue-project:$time .
docker login -u $DOCKER_LOGIN_USERNAME -p $DOCKER_LOGIN_PASSWORD 39.105.212.14:8082
docker push 39.105.212.14:8082/vue-project:$time

修改前,构建失败

修改后脚本

// 更新后
#!/bin/sh -l
npm install --registry=https://registry.npm.taobao.org
npm run build
time=$(date "+%Y%m%d%H%M%s")
docker build -t 47.94.92.122:8082/vue-project:$time .
docker login -u $DOCKER_LOGIN_USERNAME -p $DOCKER_LOGIN_PASSWORD 47.94.92.122:8082
docker push 47.94.92.122:8082/vue-project:$time

修改后,构建成功,配置修改为正确

2,docker 配置更新,更新私有库注册列表

// 解决 http 问题
[root@iZ2ze7rkgit9zoa18pxu73Z ~]# vi /etc/docker/daemon.json // 添加不安全的仓库地址:insecure-registries
{"insecure-registries":["47.94.92.122:8082"],"registry-mirrors": ["https://fwvjnv59.mirror.aliyuncs.com"]
}// 重启 docker
[root@iZ2ze7rkgit9zoa18pxu73Z bin]# systemctl restart docker

后面的贴过来,不测试了:

// 测试镜像推送
[root@iZ2ze7rkgit9zoa18pxu73Z ~]# docker push 39.105.212.14:8082/vue-project:2021123011191640834385
The push refers to repository [39.105.212.14:8082/vue-project]
530879695cfc: Preparing 
b0a31e56a1ef: Preparing 
332fa54c5886: Preparing 
6ba094226eea: Preparing 
6270adb5794c: Preparing 
unauthorized: access to the requested resource is not authorized// 解决授权问题:登录
[root@iZ2ze7rkgit9zoa18pxu73Z ~]# docker login 39.105.212.14:8082
Username: admin
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@iZ2ze7rkgit9zoa18pxu73Z ~]# docker push 39.105.212.14:8082/vue-project:2021123011191640834385
The push refers to repository [39.105.212.14:8082/vue-project]
530879695cfc: Pushed 
b0a31e56a1ef: Pushed 
332fa54c5886: Pushed 
6ba094226eea: Pushing  15.42MB/54.05MB
6270adb5794c: Pushing  14.13MB/55.28MB

3,更新已生成的 Sercet 中的 docker-server

涉及“私有镜像库认证”使用的 Sercet :

  • 命令行创建的 Sercet : registry-auth
  • 通过文件创建的 Sercet : registry-auth-file.yaml

1)命令行创建的Sercet : registry-auth

// 原始 Sercet 的创建命令
[root@k8s-master deployment]# kubectl create secret docker-registry registry-auth \--docker-username=admin \--docker-password=****** \--docker-email=admin@example.org \--docker-server=39.105.212.14:8082
secret/registry-auth created// 查询、删除、重新创建
[root@k8s-master ~]# kubectl get secret
NAME                  TYPE                                  DATA   AGE
default-token-q4qxd   kubernetes.io/service-account-token   3      12d
registry-auth         kubernetes.io/dockerconfigjson        1      4d8h
registry-auth-file    kubernetes.io/dockerconfigjson        1      4d8h
secret-opaque         Opaque                                2      4d8h
secret-opaque-flie    Opaque                                2      4d8h// 删除
[root@k8s-master ~]# kubectl delete secret registry-auth
secret "registry-auth" deleted]// 重新创建
[root@k8s-master ~]# kubectl create secret docker-registry registry-auth \--docker-username=admin \--docker-password=****** \--docker-email=admin@example.org \--docker-server=47.94.92.122:8082
secret/registry-auth created

2)registry-auth-file.yaml

// 原始 Sercet 的创建
vi registry-auth-file.yamlapiVersion: v1
kind: Secret
metadata:name: registry-auth-file
data:.dockerconfigjson: eyJhdXRocyI6eyIzOS4xMDUuMjEyLjE0OjgwODIiOnsidXNlcm5hbWUiOiJhZG1pbiIsInBhc3N3b3JkIjoiV3pAMTk4ODA4MTgiLCJlbWFpbCI6ImFkbWluQGV4YW1wbGUub3JnIiwiYXV0aCI6IllXUnRhVzQ2VjNwQU1UazRPREE0TVRnPSJ9fX0=
type: kubernetes.io/dockerconfigjson

查看 registry-auth,使用 .dockerconfigjson 更新:

// 读取
[root@k8s-master deployment]# kubectl get secret registry-auth -o yaml
apiVersion: v1
data:.dockerconfigjson: eyJhdXRocyI6eyI0Ny45NC45Mi4xMjI6ODA4MiI6eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJXekAxOTg4MDgxOCIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5vcmciLCJhdXRoIjoiWVdSdGFXNDZWM3BBTVRrNE9EQTRNVGc9In19fQ==
kind: Secret
metadata:creationTimestamp: "2022-01-03T14:33:48Z"managedFields:- apiVersion: v1fieldsType: FieldsV1fieldsV1:f:data:.: {}f:.dockerconfigjson: {}f:type: {}manager: kubectl-createoperation: Updatetime: "2022-01-03T14:33:48Z"name: registry-authnamespace: defaultresourceVersion: "1594980"uid: 06e43c6e-7e40-4d42-ad5a-427fd0698747
type: kubernetes.io/dockerconfigjson// 解码验证
[root@k8s-master deployment]# echo eyJhdXRocyI6eyI0Ny45NC45Mi4xMjI6ODA4MiI6eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJXekAxOTg4MDgxOCIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5vcmciLCJhdXRoIjoiWVdSdGFXNDZWM3BBTVRrNE9EQTRNVGc9In19fQ== | base64 -d
{"auths":{"47.94.92.122:8082":{"username":"admin","password":"******","email":"admin@example.org","auth":"YWRtaW46V3pAMTk4ODA4MTg="}}}// 修改
[root@k8s-master deployment]# vi registry-auth-file.yaml
apiVersion: v1
kind: Secret
metadata:name: registry-auth-file
data:.dockerconfigjson: eyJhdXRocyI6eyI0Ny45NC45Mi4xMjI6ODA4MiI6eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJXekAxOTg4MDgxOCIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5vcmciLCJhdXRoIjoiWVdSdGFXNDZWM3BBTVRrNE9EQTRNVGc9In19fQ==
type: kubernetes.io/dockerconfigjson// 生效
[root@k8s-master deployment]# kubectl apply -f registry-auth-file.yaml 
secret/registry-auth-file configured// 读取
[root@k8s-master deployment]# kubectl get secret registry-auth-file -o yaml
apiVersion: v1
data:.dockerconfigjson: eyJhdXRocyI6eyI0Ny45NC45Mi4xMjI6ODA4MiI6eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJXekAxOTg4MDgxOCIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5vcmciLCJhdXRoIjoiWVdSdGFXNDZWM3BBTVRrNE9EQTRNVGc9In19fQ==
kind: Secret
metadata:annotations:kubectl.kubernetes.io/last-applied-configuration: |{"apiVersion":"v1","data":{".dockerconfigjson":"eyJhdXRocyI6eyI0Ny45NC45Mi4xMjI6ODA4MiI6eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJXekAxOTg4MDgxOCIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5vcmciLCJhdXRoIjoiWVdSdGFXNDZWM3BBTVRrNE9EQTRNVGc9In19fQ=="},"kind":"Secret","metadata":{"annotations":{},"name":"registry-auth-file","namespace":"default"},"type":"kubernetes.io/dockerconfigjson"}creationTimestamp: "2021-12-30T05:58:33Z"managedFields:- apiVersion: v1fieldsType: FieldsV1fieldsV1:f:data:.: {}f:.dockerconfigjson: {}f:metadata:f:annotations:.: {}f:kubectl.kubernetes.io/last-applied-configuration: {}f:type: {}manager: kubectl-client-side-applyoperation: Updatetime: "2021-12-30T05:58:33Z"name: registry-auth-filenamespace: defaultresourceVersion: "1595453"uid: c865aeac-daa1-425a-90d3-cfd70446ccb9
type: kubernetes.io/dockerconfigjson// 验证
[root@k8s-master deployment]# echo eyJhdXRocyI6eyI0Ny45NC45Mi4xMjI6ODA4MiI6eyJ1c2VybmFtZSI6ImFkbWluIiwicGFzc3dvcmQiOiJXekAxOTg4MDgxOCIsImVtYWlsIjoiYWRtaW5AZXhhbXBsZS5vcmciLCJhdXRoIjoiWVdSdGFXNDZWM3BBTVRrNE9EQTRNVGc9In19fQ== | base64 -d
{"auths":{"47.94.92.122:8082":{"username":"admin","password":"******","email":"admin@example.org","auth":"YWRtaW46V3pAMTk4ODA4MTg="}}}

修改后,重新生效配置,并查看 Sercet 内容完成验证;

4,更新 deployment-v4.yaml 的镜像地址

[root@k8s-master deployment]# vi deployment-v4.yamlapiVersion: apps/v1
kind: Deployment
metadata:name: v4     #修改
spec:selector:matchLabels:app: v4  #修改replicas: 1template:metadata:labels:app: v4 #修改spec: containers:- name: vue-projectimage: 47.94.92.122:8082/vue-project:2021123011191640834385   #修改ports:- containerPort: 80[root@k8s-master deployment]# kubectl apply -f deployment-v4.yaml
deployment.apps/v4 configured[root@k8s-master deployment]# kubectl get pods
NAME                       READY   STATUS             RESTARTS   AGE
user-v1-84bdcc465b-vxvl2   1/1     Running            0          4d7h
v4-57b4cf7fd9-zcl45        0/1     ImagePullBackOff   0          4d7h
v4-fb4cd75f5-bf2pf         0/1     ErrImagePull       0          33s[root@k8s-master deployment]# kubectl describe pod v4-fb4cd75f5-bf2pf
Events:Type     Reason     Age                From               Message----     ------     ----               ----               -------Normal   Scheduled  67s                default-scheduler  Successfully assigned default/v4-fb4cd75f5-bf2pf to k8s-nodeNormal   Pulling    28s (x3 over 66s)  kubelet            Pulling image "47.94.92.122:8082/vue-project:2021123011191640834385"Warning  Failed     16s (x3 over 66s)  kubelet            Failed to pull image "47.94.92.122:8082/vue-project:2021123011191640834385": rpc error: code = Unknown desc = Error response from daemon: Get "https://47.94.92.122:8082/v2/": http: server gave HTTP response to HTTPS clientWarning  Failed     16s (x3 over 66s)  kubelet            Error: ErrImagePullNormal   BackOff    4s (x3 over 66s)   kubelet            Back-off pulling image "47.94.92.122:8082/vue-project:2021123011191640834385"Warning  Failed     4s (x3 over 66s)   kubelet            Error: ImagePullBackOff

生效配置,进入pod验证拉取镜像时,实际访问的镜像地址:47.94.92.122 修改生效

5,本地镜像仓库列表

删除无效的老地址镜像

[root@iZ2ze7rkgit9zoa18pxu73Z bin]# docker image ls
REPOSITORY                       TAG                      IMAGE ID       CREATED       SIZE
39.105.212.14:8082/vue-project   2021123011191640834385   cf09bb54e87e   4 days ago    110MB
39.105.212.14:8082/vue-project   2021123011461640835990   cf09bb54e87e   4 days ago    110MB
39.105.212.14:8082/vue-project   2022010316221641198128   cf09bb54e87e   4 days ago    110MB
47.94.92.122:8082/vue-project    2022010316241641198261   cf09bb54e87e   4 days ago    110MB
cicdproject                      latest                   2e9269d7c724   2 weeks ago   110MB
node                             latest                   058747996654   4 weeks ago   992MB
nginx                            1.15                     53f3fd8007f7   2 years ago   109MB

四,结尾

本篇,介绍了 ci-server 服务器重启后的环境修复;

下一篇,介绍 k8s 的服务间调用,k8s 服务发现;

相关内容

热门资讯

《狼图腾》适合孩子们读吗?这本... 《狼图腾》适合孩子们读吗?这本书会改变孩子们的三观吗?我觉得这部书是非常适合孩子们读的事,会改变孩子...
谁能给几个著名企业家的演讲视频... 谁能给几个著名企业家的演讲视频呀?只要是针对如何工作,创业等等相关的都可以呀~! 在大学里的演讲也行...
高手来翻译~! 高手来翻译~!翻译?你是外国人吗?分给少了 嘿嘿
男生说女生的声音比刚认识她时听... 男生说女生的声音比刚认识她时听着更成熟了是什么意思说明你以前说话不成熟呗!说你现在比以前成熟了,不像...
求音乐:会走没有腿,会说没有嘴... 求音乐:会走没有腿,会说没有嘴 是哪首歌的词楼上是个煞白 放他的屁 话说 有这个歌词么 是...
小孩子长时间看电视现在开始不爱... 小孩子长时间看电视现在开始不爱搭理人了 怎么办看得什么节目啊。你也不怕影响孩子的视力,马上转移孩子的...
清净心,源于己.什么意思? 清净心,源于己.什么意思?要想获得宁静的心境或者要使自己内心平和,要得从自身出发,要先调整或改变自己...
茅山术该看什么书? 茅山术该看什么书?想知道有多么神奇看《鲁班书》。这本书确实神奇。只是据说学会此书的人会没后代。所以我...
贾平凹秦腔阅读答案 贾平凹秦腔阅读答案1、双摇、单摇、上下飞闪、纹丝不动、猛转2、比喻。表现了广大人民群众对秦腔的热爱。...
故事很长,余生很久是什么意思? 故事很长,余生很久是什么意思?代表只要人还活着!就有发生不完的故事!
我的爸爸是森林之王观后感英文? 我的爸爸是森林之王观后感英文?我的爸爸是森林之王观后感My father was Wangguanh...
起凡群雄逐鹿开锦囊能开什么 起凡群雄逐鹿开锦囊能开什么跪求 起凡群雄逐鹿开锦囊能开什么各种各样的装备:力量,大地,(左边的是要...
什么是仲裁者? 什么是仲裁者?到底是什么的?好像很有名的样子在广西常常听人提起。仲裁者 公认的第三者在争端两方间...
是不是只要付出真心就同样可以换... 是不是只要付出真心就同样可以换回真心?是的诚心能让石头落泪真诚能让枯木发芽只要我们付出真心会有回报的...
描写小女孩聪明的文言文? 描写小女孩聪明的文言文?朓尝宿卫,还过江革,时大雪,见革弊絮单席,而耽学不倦,嗟叹久之,乃脱所著襦,...
自哀自怜是什么意思? 自哀自怜是什么意思?有没有写错字?自艾自怜是:艾的读音为yi,第四声 艾的意思是改正。 从字形上看,...
《天涯论坛》红中麻将群@拉我(... 1.亮点:一元红中麻将微信“群”—ab120590—hf420624—mj120590—客服Q443...
围观广东24小时在线一元麻将群 好运连连,全网推荐:(ab120590)(mj120590)【hf420624】-Q号:(QQ443...
[天天通知]手机红中麻将@群(... 1.进群方式《ab120590》或者《mj120590》《hf420624》--QQ(4434063...
重大通知如何加人24小时1块1... 认证群主微信微【ab120590】 【mj120590】【hf420624】(一元俩元红中麻将)(跑...