当前位置: 首页 > news >正文

WordPress的网外无法访问成都seo工程师

WordPress的网外无法访问,成都seo工程师,设计培训网站建设,关于建设商城网站费用在上一篇文章中 springboot service如何动态读取外部配置文件 介绍了springboot 中如何实时读取外部配置文件的内容 部署在K8S 接下来我把它部署在k8s 首先, 我们把配置文件放入项目某个目录 这步部是必须的, 毕竟我们要引入是项目外部的文件&#xf…

在上一篇文章中
springboot service如何动态读取外部配置文件

介绍了springboot 中如何实时读取外部配置文件的内容



部署在K8S

接下来我把它部署在k8s



首先, 我们把配置文件放入项目某个目录

这步部是必须的, 毕竟我们要引入是项目外部的文件, 这一步只是方便在不同CICD 环境下的docker 构建
我们就放在 src 外面的configs folder
在这里插入图片描述


修改docker file

# use the basic openjdk image
FROM openjdk:17# setup working directory
WORKDIR /app# create /app/config
RUN mkdir -p /app/config/config2# copy configs files from project folder to /app/config
# When using COPY with more than one source file, the destination must be a directory and end with a /
COPY configs/external-config.properties /app/config/
COPY configs/external-config2.properties /app/config/config2/# copy and rename jar file into container
COPY target/*.jar app.jar# expose port
EXPOSE 8080# define environment variable, and provide a default value
ENV APP_ENVIRONMENT=dev# define the default startup command, it could be overridden in k8s
# CMD java -jar -Dserver.port=8080 -Dspring.config.name=application-${APP_ENVIRONMENT} app.jar
CMD java -jar -Dserver.port=8080 app.jar --spring.profiles.active=${APP_ENVIRONMENT}

需要创建/app/configs 并把配置文件复制到这里, 因为springboot service 会从这个path读取
注意有两个config 文件, 他们并不在同1个folder
external-config2.properties 在subfolder config2里面



构建镜像和部署镜像到GAR

这一步我们用google cloudbuild 完成
至于cloudbuild 的介绍请参考
初探 Google 云原生的CICD - CloudBuild

cloudbuild-gcr.yaml

# just to update the docker image to GAR with the pom.xml versionsteps:- id: run maven installname: maven:3.9.6-sapmachine-17 # https://hub.docker.com/_/mavenentrypoint: bashargs:- '-c'- |whoamiset -xpwdmvn installcat pom.xml | grep -m 1 "<version>" | sed -e 's/.*<version>\([^<]*\)<\/version>.*/\1/' > /workspace/version.txtecho "Version: $(cat /workspace/version.txt)"- id: build and push docker imagename: 'gcr.io/cloud-builders/docker'entrypoint: bashargs:- '-c'- |set -xecho "Building docker image with tag: $(cat /workspace/version.txt)"docker build -t $_GAR_BASE/$PROJECT_ID/$_DOCKER_REPO_NAME/${_APP_NAME}:$(cat /workspace/version.txt) .docker push $_GAR_BASE/$PROJECT_ID/$_DOCKER_REPO_NAME/${_APP_NAME}:$(cat /workspace/version.txt)logsBucket: gs://jason-hsbc_cloudbuild/logs/
options: # https://cloud.google.com/cloud-build/docs/build-config#optionslogging: GCS_ONLY # or CLOUD_LOGGING_ONLY https://cloud.google.com/cloud-build/docs/build-config#loggingsubstitutions:_DOCKER_REPO_NAME: my-docker-repo_APP_NAME: cloud-order_GAR_BASE: europe-west2-docker.pkg.dev

部署完成后, 我们得到1个gar的对应image的url
europe-west2-docker.pkg.dev/jason-hsbc/my-docker-repo/cloud-order:1.1.0



编写k8s yaml 和部署到k8s

apiVersion: apps/v1
kind: Deployment
metadata:labels: # label of this deploymentapp: cloud-order # custom definedauthor: nvd11name: deployment-cloud-order # name of this deploymentnamespace: default
spec:replicas: 3            # desired replica count, Please note that the replica Pods in a Deployment are typically distributed across multiple nodes.revisionHistoryLimit: 10 # The number of old ReplicaSets to retain to allow rollbackselector: # label of the Pod that the Deployment is managing,, it's mandatory, without it , we will get this error # error: error validating data: ValidationError(Deployment.spec.selector): missing required field "matchLabels" in io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector ..matchLabels:app: cloud-orderstrategy: # Strategy of upodatetype: RollingUpdate # RollingUpdate or RecreaterollingUpdate:maxSurge: 25% # The maximum number of Pods that can be created over the desired number of Pods during the updatemaxUnavailable: 25% # The maximum number of Pods that can be unavailable during the updatetemplate: # Pod templatemetadata:labels:app: cloud-order # label of the Pod that the Deployment is managing. must match the selector, otherwise, will get the error Invalid value: map[string]string{"app":"bq-api-xxx"}: `selector` does not match template `labels`spec: # specification of the Podcontainers:- image: europe-west2-docker.pkg.dev/jason-hsbc/my-docker-repo/cloud-order:1.1.0 # image of the containerimagePullPolicy: Alwaysname: container-cloud-ordercommand: ["bash"]args: - "-c"- |java -jar -Dserver.port=8080 app.jar --spring.profiles.active=$APP_ENVIRONMENTenv: # set env varaibles- name: APP_ENVIRONMENT # name of the environment variablevalue: prod # value of the environment variablerestartPolicy: Always # Restart policy for all containers within the PodterminationGracePeriodSeconds: 10 # The period of time in seconds given to the Pod to terminate gracefully

没什么特别

部署:

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl apply -f deployment-cloud-order-with-subpath.yaml 
deployment.apps/deployment-cloud-order created
gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl get pods
NAME                                         READY   STATUS      RESTARTS       AGE
deployment-bq-api-service-6f6ffc7866-8djx9   1/1     Running     3 (12d ago)    17d
deployment-bq-api-service-6f6ffc7866-g4854   1/1     Running     12 (12d ago)   61d
deployment-bq-api-service-6f6ffc7866-lwxt7   1/1     Running     14 (12d ago)   63d
deployment-bq-api-service-6f6ffc7866-mxwcq   1/1     Running     11 (12d ago)   61d
deployment-cloud-order-58ddcf894d-8pjsz      1/1     Running     0              5s
deployment-cloud-order-58ddcf894d-mp4js      1/1     Running     0              5s
deployment-cloud-order-58ddcf894d-sszjd      1/1     Running     0              5s

检查容器内的配置文件:

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl exec -it deployment-cloud-order-58ddcf894d-8pjsz -- /bin/bash
bash-4.4# pwd
/app
bash-4.4# ls config
config2  external-config.properties
bash-4.4# ls config/config2/
external-config2.properties
bash-4.4# 



测试api

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ curl http://www.jp-gcp-vms.cloud:8085/cloud-order/actuator/info | jq .% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  1842    0  1842    0     0   1827      0 --:--:--  0:00:01 --:--:--  1829
{"app": "Cloud Order Service","appEnvProfile": "prod","version": "1.1.0","hostname": "deployment-cloud-order-58ddcf894d-8pjsz","dbUrl": "jdbc:mysql://192.168.0.42:3306/demo_cloud_order?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true","description": "This is a simple Spring Boot application to for cloud order...","customConfig1": "value of config1","customConfig2": "value of config2",}
}

注意 customConfig1 和 customConfig2 的值, 部署是成功的



For customConfig2 使用configMap

由于customConfig2 是实时更新的
我们尝试用configmap 来取代 上面external-config2.properties 的配置
注意这里的值改成 value of config2 - from k8s configmap 方便区分



构建1个external-config2 的configmap 资源对象

configmap-cloud-order-external-config2.yaml

apiVersion: v1
kind: ConfigMap
metadata:name: configmap-cloud-order-external-config2
data:external.custom.config2: external.custom.config2=value of config2 - from k8s configmap

部署:

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl apply -f configmap-cloud-order-external-config2.yaml 
configmap/configmap-cloud-order-external-config2 created
gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl describe cm configmap-cloud-order-external-config2
Name:         configmap-cloud-order-external-config2
Namespace:    default
Labels:       <none>
Annotations:  <none>Data
====
external.custom.config2:
----
external.custom.config2=value of config2 - from k8s configmapBinaryData
====Events:  <none>



修改deployment yaml 引入configmap

apiVersion: apps/v1
kind: Deployment
metadata:labels: # label of this deploymentapp: cloud-order # custom definedauthor: nvd11name: deployment-cloud-order # name of this deploymentnamespace: default
spec:replicas: 3            # desired replica count, Please note that the replica Pods in a Deployment are typically distributed across multiple nodes.revisionHistoryLimit: 10 # The number of old ReplicaSets to retain to allow rollbackselector: # label of the Pod that the Deployment is managing,, it's mandatory, without it , we will get this error # error: error validating data: ValidationError(Deployment.spec.selector): missing required field "matchLabels" in io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector ..matchLabels:app: cloud-orderstrategy: # Strategy of upodatetype: RollingUpdate # RollingUpdate or RecreaterollingUpdate:maxSurge: 25% # The maximum number of Pods that can be created over the desired number of Pods during the updatemaxUnavailable: 25% # The maximum number of Pods that can be unavailable during the updatetemplate: # Pod templatemetadata:labels:app: cloud-order # label of the Pod that the Deployment is managing. must match the selector, otherwise, will get the error Invalid value: map[string]string{"app":"bq-api-xxx"}: `selector` does not match template `labels`spec: # specification of the Podcontainers:- image: europe-west2-docker.pkg.dev/jason-hsbc/my-docker-repo/cloud-order:1.1.0 # image of the containerimagePullPolicy: Alwaysname: container-cloud-ordercommand: ["bash"]args: - "-c"- |java -jar -Dserver.port=8080 app.jar --spring.profiles.active=$APP_ENVIRONMENTenv: # set env varaibles- name: APP_ENVIRONMENT # name of the environment variablevalue: prod # value of the environment variablevolumeMounts:- name: volume-external-config2mountPath: /app/config/config2/volumes:- name: volume-external-config2configMap:name: configmap-cloud-order-external-config2items:- key: external.custom.config2path: external-config2.properties # name of the file to be mountedrestartPolicy: Always # Restart policy for all containers within the PodterminationGracePeriodSeconds: 10 # The period of time in seconds given to the Pod to terminate gracefully

注意这里使用了 volume 和 volumemount



重新部署 cloud-order service

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl delete deploy deployment-cloud-order
deployment.apps "deployment-cloud-order" deleted
gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl apply -f deployment-cloud-order-with-subpath.yaml 
deployment.apps/deployment-cloud-order created



测试api

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ curl http://www.jp-gcp-vms.cloud:8085/cloud-order/actuator/info | jq .% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  1863    0  1863    0     0   3888      0 --:--:-- --:--:-- --:--:--  3889
{"app": "Cloud Order Service","appEnvProfile": "prod","version": "1.1.0","hostname": "deployment-cloud-order-69d4cd76d6-hwtfj","dbUrl": "jdbc:mysql://192.168.0.42:3306/demo_cloud_order?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true","description": "This is a simple Spring Boot application to for cloud order...","customConfig1": "value of config1","customConfig2": "value of config2 - from k8s configmap",

并没什么大问题, 证明configmap 的配置是可以覆盖docker里面定义的配置文件的



实时修改configmap 的配置

这时我们修改一下 configmap configmap-cloud-order-external-config2 里的值
由 external.custom.config2: external.custom.config2=value of config2 - from k8s configmap
改成 external.custom.config2: external.custom.config2=value of config2 - from k8s configmap updated!

apiVersion: v1
kind: ConfigMap
metadata:name: configmap-cloud-order-external-config2
data:external.custom.config2: external.custom.config2=value of config2 - from k8s configmap updated!

更新:

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl apply -f configmap-cloud-order-external-config2.yaml 
configmap/configmap-cloud-order-external-config2 configured

等半分钟后 (1是 k8s 需要时间把 configmap的值刷新到 pods里的volumes, 2时是springboot本身需要定时器去重新获取值)
再测试api

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ curl http://www.jp-gcp-vms.cloud:8085/cloud-order/actuator/info | jq .% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  1872    0  1872    0     0   3900      0 --:--:-- --:--:-- --:--:--  3900
{"app": "Cloud Order Service","appEnvProfile": "prod","version": "1.1.0","hostname": "deployment-cloud-order-69d4cd76d6-qj98f","dbUrl": "jdbc:mysql://192.168.0.42:3306/demo_cloud_order?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true","description": "This is a simple Spring Boot application to for cloud order...","customConfig1": "value of config1","customConfig2": "value of config2 - from k8s configmap updated!",

果然customConfig2的值自动更新了, 正是我们想要的
而且容器里的文件也的确更新了

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl exec -it deployment-cloud-order-69d4cd76d6-hwtfj -- /bin/bash
bash-4.4# pwd
/app
bash-4.4# ls config
config2  external-config.properties
bash-4.4# cat config/config2/external-config2.properties 
external.custom.config2=value of config2 - from k8s configmap updated!



volumes mount 会覆盖整个文件夹(其他文件被删除)

下面来点整活
我们修改一下deployment 的yaml 配置, 把configmap的值 mark成另1个文件名

  volumeMounts:- name: volume-external-config2mountPath: /app/config/config2/volumes:- name: volume-external-config2configMap:name: configmap-cloud-order-external-config2items:- key: external.custom.config2path: external-config2-1.properties # name of the file to be mounted

按照设想, 容器内的configmap里的
/app/config/config2/ 文件内将会有两个文件

dockerfile 定义的external-config2.properties
和 k8s 定义的 external-config2-1.properties

实际部署测试:

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ curl http://www.jp-gcp-vms.cloud:8085/cloud-order/actuator/info | jq .% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100  1837    0  1837    0     0    926      0 --:--:--  0:00:01 --:--:--   926
{"app": "Cloud Order Service","appEnvProfile": "prod","version": "1.1.0","hostname": "deployment-cloud-order-6878b85d44-cdvlc","dbUrl": "jdbc:mysql://192.168.0.42:3306/demo_cloud_order?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true","description": "This is a simple Spring Boot application to for cloud order...","customConfig1": "value of config1","customConfig2": "not defined",

customConfig2 居然是not defined
检查容器
发现 external-config2.properties 没了

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl exec -it deployment-cloud-order-6878b85d44-cdvlc -- /bin/bash
bash-4.4# ls
app.jar  config
bash-4.4# ls config
config2  external-config.properties
bash-4.4# ls config/config2/
external-config2-1.properties
bash-4.4# 

原因是 当k8s 把 volume volume-external-config2 mount在 /app/config/config2 中的时候, 原来的文件就会消失



尝试把新文件mount到1个subfolder

解决方法1:
把 volume volume-external-config2 mount在 /app/config/config2/config-sub
应该可以解决

我们修改deployment yaml

  volumeMounts:- name: volume-external-config2mountPath: /app/config/config2/config-subvolumes:- name: volume-external-config2configMap:name: configmap-cloud-order-external-config2items:- key: external.custom.config2path: external-config2-1.properties # name of the file to be mounted

mountPath 改成了/app/config/config2/config-sub

这种方法是可行的

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl exec -it deployment-cloud-order-654974f855-cmdz7 -- /bin/bash
bash-4.4# ls
app.jar  config
bash-4.4# cd config
bash-4.4# ls
config2  external-config.properties
bash-4.4# cd config2
bash-4.4# ls
config-sub  external-config2.properties
bash-4.4# cd config-sub
bash-4.4# ls
external-config2-1.properties
bash-4.4# 

而且证明了, mountpath中的路径不存在的话, k8s会尝试创建。



利用subpath 去把文件mount在同样的folder

但是上面的做法, 能把新文件mount在1个字母中, 的确不会另旧文件消失,但是并直接真正解决问题

K8S 提供了subpath 的方法:
我们修改deployment yaml

        volumeMounts:- name: volume-external-config2mountPath: /app/config/config2/external-config2-1.properties # if we need to use subpath, need to provide the filename as wellsubPath: external-config2-1.properties # name of the file to be mounted, if we use subpath, the other files in that same folder will not dispearvolumes:- name: volume-external-config2configMap:name: configmap-cloud-order-external-config2items:- key: external.custom.config2path: external-config2-1.properties # name of the file to be mounted                                                               

注意这里有两个改动:

  1. mountpath 上加上了文件名
  2. 添加subpath 配置, 其值还是文件名

这次的确能令两个配置文件同时存在, 原来的文件external-config2.properties 并没有被抹除

gateman@MoreFine-S500:~/projects/coding/k8s-s/service-case/cloud-order$ kubectl exec -it deployment-cloud-order-7775b8c7cd-jnv7v -- /bin/bash
bash-4.4# pwd
/app
bash-4.4# ls
app.jar  config
bash-4.4# ls config
config2  external-config.properties
bash-4.4# ls config/config2/
external-config2-1.properties  external-config2.properties
bash-4.4# 



subpath的一些限制

k8s 设计的 subpath 其实并不是那么直接
参考:
https://hackmd.io/@maelvls/kubernetes-subpath?utm_source=preview-mode&utm_medium=rec

第1个限制就是 subpath 只能1个文件1个文件地mount, 不支持mount整个folder

参考:
https://kubernetes.io/docs/concepts/configuration/configmap/

第2个限制就是, 用subpath mount的configmap , 即使configmap的值被外部修改, 也不会同步到容器…


文章转载自:
http://twerp.jftL.cn
http://singulative.jftL.cn
http://bogbean.jftL.cn
http://mdap.jftL.cn
http://leisured.jftL.cn
http://sciuroid.jftL.cn
http://liveability.jftL.cn
http://enumerable.jftL.cn
http://cypsela.jftL.cn
http://turpitude.jftL.cn
http://hubless.jftL.cn
http://impostor.jftL.cn
http://debouchment.jftL.cn
http://arguer.jftL.cn
http://sarcastic.jftL.cn
http://composedly.jftL.cn
http://fetial.jftL.cn
http://carfax.jftL.cn
http://frugal.jftL.cn
http://feat.jftL.cn
http://cadenza.jftL.cn
http://dost.jftL.cn
http://stipes.jftL.cn
http://coupon.jftL.cn
http://episperm.jftL.cn
http://proestrus.jftL.cn
http://bobstay.jftL.cn
http://siphunculated.jftL.cn
http://nile.jftL.cn
http://subgiant.jftL.cn
http://pursuance.jftL.cn
http://housebroke.jftL.cn
http://succour.jftL.cn
http://sporadically.jftL.cn
http://magnetotail.jftL.cn
http://beggarweed.jftL.cn
http://armonica.jftL.cn
http://feckly.jftL.cn
http://chorist.jftL.cn
http://concentric.jftL.cn
http://bintree.jftL.cn
http://noiseproof.jftL.cn
http://carefully.jftL.cn
http://fragrance.jftL.cn
http://pottage.jftL.cn
http://defender.jftL.cn
http://bergamasca.jftL.cn
http://assertory.jftL.cn
http://chin.jftL.cn
http://oland.jftL.cn
http://duograph.jftL.cn
http://germicidal.jftL.cn
http://limb.jftL.cn
http://aldo.jftL.cn
http://unpersuasive.jftL.cn
http://friday.jftL.cn
http://nostologic.jftL.cn
http://qb.jftL.cn
http://araby.jftL.cn
http://marsha.jftL.cn
http://xenogenesis.jftL.cn
http://firedrake.jftL.cn
http://digitated.jftL.cn
http://congealer.jftL.cn
http://berat.jftL.cn
http://presbyope.jftL.cn
http://furriery.jftL.cn
http://stub.jftL.cn
http://septemia.jftL.cn
http://photochromism.jftL.cn
http://banderole.jftL.cn
http://buskined.jftL.cn
http://emotionless.jftL.cn
http://ventrotomy.jftL.cn
http://serous.jftL.cn
http://hydrogen.jftL.cn
http://applausively.jftL.cn
http://logoff.jftL.cn
http://sublunar.jftL.cn
http://myall.jftL.cn
http://diesel.jftL.cn
http://swahili.jftL.cn
http://durbar.jftL.cn
http://electrocapillarity.jftL.cn
http://tetracycline.jftL.cn
http://robert.jftL.cn
http://multiflorous.jftL.cn
http://plumule.jftL.cn
http://perfectness.jftL.cn
http://omnirange.jftL.cn
http://mizzen.jftL.cn
http://restuff.jftL.cn
http://hyperpyretic.jftL.cn
http://logginess.jftL.cn
http://chemisorb.jftL.cn
http://astrodome.jftL.cn
http://cording.jftL.cn
http://irresistible.jftL.cn
http://lusty.jftL.cn
http://interestedly.jftL.cn
http://www.dt0577.cn/news/90902.html

相关文章:

  • 专业建站提供商b站新人视频怎么推广
  • 如何设计响应式布局网站搜索引擎分类
  • 用源码搭建网站合肥百度快照优化排名
  • 网站怎样运营如何快速推广一个新产品
  • 做网站买什么书核心关键词和长尾关键词
  • 河北省城乡和建设厅网站交换免费连接
  • 什么叫响应式网站网址关键词查询网站
  • 专业网站制作设计公司哪家好想要推广页
  • 如果只做p2p种子搜索网站直通车关键词怎么优化
  • 临沂网站建设公司全国百度小说搜索排行榜
  • 杭州 手机网站今日新闻播报
  • 有经验的番禺网站建设百度爱采购推广效果怎么样?
  • 设计师招聘网站推荐seo人员招聘
  • 网页截图快捷键ctrl成都有实力的seo团队
  • 网站设计实验北京seo优化wyhseo
  • 网站图片滚动咋么做网络营销的seo是做什么的
  • 网站推广行业赚钱吗烟台百度推广公司
  • 资源共享网站怎么做友情链接可以随便找链接加吗
  • 旅游网站建设公司排名淘宝运营培训课程
  • 网站制作一条龙关键词优化系统
  • 常州找工作哪个网站好刷神马关键字排名软件
  • 巩义专业网站建设价格营销渠道名词解释
  • 盐城快速建设网站找哪家seo流量排名软件
  • 莱芜都市网旗下论坛seo免费诊断电话
  • 汇编语言做网站互联网营销具体做什么
  • 网站的在线qq客服链接怎么做今日头条收录入口
  • wordpress数据库排序规则临沂seo优化
  • 中职学校专业建设规划网络推广与优化
  • 四川日报比选网seo的主要分析工具
  • wordpress 主题黑广州seo招聘信息