我正在尝试创建并运行一个buildconfig yml文件。
C:\OpenShift>oc version
Client Version: 4.5.31
Kubernetes Version: v1.18.3+65bd32d我有多个Springboot WebUI应用程序,需要部署在OpenShift上
要为每个应用程序拥有单独的配置yml文件集(映像流、buildconfig、部署配置、服务、路由),似乎效率很低。
相反,我希望有一组参数化的yml文件,通过这些文件可以传递自定义参数来设置每个单独的应用程序。
目前为止的
第一版
Dockerfile-
FROM org/rhelImage
USER root
# Install Yum Packages
RUN yum -y install\
net-tools\
&& yum -y install nmap-ncat\
RUN curl -s --create-dirs --insecure -L ${ARTIFACTURL} -o ${APPPATH}/${ARTIFACT}
# Add docker-entrypoint.sh to the image
ADD docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod -Rf 775 /app && chmod 775 /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
RUN chmod -R g+rx /app
# Expose port
EXPOSE $MY_PORT
# Set working directory when container starts
WORKDIR $APPPATH
# Starting the applicaiton using ENTRYPOINT
#ENTRYPOINT ["sh","/docker-entrypoint.sh"]
$ oc create configmap myapp-configmap --from-env-file=MyApp.properties
configmap/myapp-configmap created
$ oc describe cm myapp-configmap
Name: myapp-configmap
Namespace: 1234
Labels: <none>
Annotations: <none>
Data
====
APPPATH:
----
/app
ARTIFACT:
----
myapp.jar
ARTIFACTURL:
----
"https://myorg/1.2.3.4/myApp-1.2.3.4.jar"
MY_PORT:
----
12305
Events: <none> buildconfig.yaml片段
strategy:
dockerStrategy:
env:
- name: GIT_SSL_NO_VERIFY
value: "true"
- name: ARTIFACTURL
valueFrom:
configMapKeyRef:
name: "myapp-configmap"
key: ARTIFACTURL
- name: ARTIFACT
valueFrom:
configMapKeyRef:
name: "myapp-configmap"
key: ARTIFACT这个很好用。但是,我需要在文件中包含这些env:变量。
我这样做是为了具有更大的灵活性,也就是说,我在docker文件中引入了一个新变量,我不需要更改buildconfig.yml --我只是在属性文件中添加了新的键:值对,然后重新构建,我们就可以继续了。
这就是我接下来要做的事;
第二版
Dockerfile
FROM org/rhelImage
USER root
# Install Yum Packages
RUN yum -y install\
net-tools\
&& yum -y install nmap-ncat\
#Intializing the variables file;
RUN ["sh", "-c", "source ./MyApp.properties"]
RUN curl -s --create-dirs --insecure -L ${ARTIFACTURL} -o ${APPPATH}/${ARTIFACT}
# Add docker-entrypoint.sh to the image
ADD docker-entrypoint.sh /docker-entrypoint.sh
RUN chmod -Rf 775 /app && chmod 775 /docker-entrypoint.sh
RUN chmod +x /docker-entrypoint.sh
RUN chmod -R g+rx /app
# Expose port
EXPOSE $MY_PORT
# Set working directory when container starts
WORKDIR $APPPATH
# Starting the applicaiton using ENTRYPOINT
#ENTRYPOINT ["sh","/docker-entrypoint.sh"]
$ oc create configmap myapp-configmap --from-env-file=MyApp.properties=C:\MyRepo\MyTemplates\MyApp.properties
configmap/myapp-configmap created
C:\OpenShift>oc describe configmaps test-configmap
Name: myapp-configmap
Namespace: 1234
Labels: <none>
Annotations: <none>
Data
====
MyApp.properties:
----
APPPATH=/app
ARTIFACTURL="https://myorg/1.2.3.4/myApp-1.2.3.4.jar"
ARTIFACT=myapp.jar
MY_PORT=12035
Events: <none> buildconfig.yaml片段
source:
contextDir: "${param_source_contextdir}"
configMaps:
- configMap:
name: "${param_app_name}-configmap"但是,构建失败。
STEP 9: RUN ls ./MyApp.properties
ls: cannot access ./MyApp.properties: No such file or directory
error: build error: error building at STEP "RUN ls ./MyApp.properties": error while running runtime: exit status 2 这意味着配置映射文件没有复制到文件夹。
请你建议下一步该怎么做好吗?
发布于 2021-06-19 23:02:09
我想你有点误会Openshift了。你说的第一件事
对于每个应用程序来说,拥有单独的配置yml文件集(映像流、buildconfig、部署配置、服务、路由)似乎效率很低。
但这就是kubernetes/openshift的工作原理。如果您的资源文件看起来相同,但只使用不同的git资源或图像,那么您可能正在寻找Openshift模板。
相反,我希望有一组参数化的yml文件,通过这些文件,我可以传递自定义参数来设置每个应用程序。
是的,我认为Openshift模板就是你要找的。如果将模板上载到服务目录,则只要有新的应用程序要部署,就可以在UI中添加一些变量,然后单击deploy。
Openshift模板只是所有openshift资源(configmap、service、buildconfig等)的参数化文件。如果您的应用程序需要使用某些凭据从git构建,则可以将这些变量参数化。
但也请看一下Openshift的源代码到图像解决方案(我不确定您使用的是哪个版本,所以您必须搜索一些资源)。它可以构建和部署您的应用程序,而无需编写您自己的资源文件。
https://stackoverflow.com/questions/68041418
复制相似问题