我有一个在docker容器上运行的弹簧靴微服务,下面是dockerfile
FROM java:8-jre
MAINTAINER <>
WORKDIR deploy/
#COPY config/* /deploy/config/
COPY ./ms.console.jar /deploy/
CMD chmod +R 777 ./ms.console.jar
CMD ["java","-jar","/deploy/ms.console.jar","console"]
EXPOSE 8384
在这里,我的配置存储在外部文件夹中,即/config/console-server.yml
,当我启动应用程序时,它将在内部加载配置(Spring Boot功能(。
现在,我想使用ConfigMap分开此配置,因为我只是创建了一个ConfigMap并存储所有配置详细信息。
kubectl创建configmap console-configmap -from-file =。/config/console-server.yml
kubectl描述configmap console-configmap
以下是描述详细信息:
Name: console-configmap
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
console-server.yml:
----
server:
http:
port: 8385
compression:
enabled: true
mime-types: application/json,application/xml,text/html,text/xml,text/plain,text/css,application/javascript
min-response-size: 2048
---
spring:
thymeleaf:
prefix: classpath:/static
application:
name: console-service
profiles:
active: native
servlet:
multipart:
max-file-size: 30MB
max-request-size: 30MB
---
host:
gateway: http://apigateway:4000
webhook: http://localhost:9000
我的部署yml是:
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: consoleservice1
spec:
selector:
matchLabels:
app: consoleservice
replicas: 1 # tells deployment to run 3 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
app: consoleservice
spec:
containers:
- name: consoleservice
image: ms-console
ports:
- containerPort: 8384
imagePullPolicy: Always
envFrom:
- configMapRef:
name: console-configmap
imagePullSecrets:
- name: regcresd
我的疑问是,我在Dockerfile中评论了Config文件夹,因此在运行Pods时,由于没有配置而引发了例外,我将如何将此机程configmap注入我的部署,我尝试过的是已经共享的,但是要遇到相同的问题。
首先,您如何在应用程序中使用.yml文件?如果您将YML文件内容作为环境变量消耗,则配置应正常工作。但是我怀疑您想从容器内的配置文件中消耗内容。如果是这种情况,则必须从ConfigMap中创建一个卷,如下所示:
apiVersion: apps/v1 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
name: consoleservice1
spec:
selector:
matchLabels:
app: consoleservice
replicas: 1 # tells deployment to run 3 pods matching the template
template: # create pods using pod definition in this template
metadata:
labels:
app: consoleservice
spec:
containers:
- name: consoleservice
image: ms-console
ports:
- containerPort: 8384
imagePullPolicy: Always
volumeMounts:
- mountPath: /app/config
name: config
volumes:
- name: config
configMap:
name: console-configmap
imagePullSecrets:
- name: regcresd
该文件将在路径/app/config/console-server.yml
中可用。您必须根据需要对其进行修改。
您需要加载键:从配置文件作为环境变量的值对,然后规格下方可以正常工作
envFrom:
- configMapRef:
name: console-configmap
如果您需要config作为pod中的文件,则将configmap安装为卷。以下链接将很有帮助https://kubernetes.io/docs/tutorials/configuration/configure-redis-using-configmap/