[英]Dockerize vue js front end and spring boot backend and deploy on kubernetes cluster
我开发了 spring boot 后端和vue
js
前端我可以成功部署 spring boot 应用程序并为 spring boot 应用程序创建集群ip
服务,但我从未在kubernetes
和kubernetes
上使用 NPM 项目。 我也有问题, Axios
,当我在本地测试后端和前端,我给(localhost:backendport/endpoint)
为axios
,我怎么能适应kubernetes
。 我应该给集群ip
服务名称而不是localhost:port/endpoint -> clusteripservice/endpoint
如果是这样,我如何将配置外部化以及如何部署这两个应用程序。
这是Axios
电话
import axios from 'axios'
const API_URL = 'http://localhost:8084'
//const API_URL = '/'
class UserDataService {
retrieveAllUsers() {
return axios.get(`${API_URL}/user/getall`);
}
}
export default new UserDataService()
想法是使用 nginx 作为您的应用程序容器和代理传递到代理到后端。 所以你需要为你的 api 定义位置,即 /api 和代理。
然后如果你使用 axios,你会在相对路径上调用所有后端端点,即
axios.get('/api/v1/myApiPath')
因此,您无需担心后端调用中的主机名。
此外,对于开发,您同样使用 vue.js 开发设置也通过 npm 代理后端。
在这里查看我的玩具项目的详细信息:部署部分 - https://github.com/taleodor/mafia-deployment UI 部分 - https://github.com/taleodor/mafia-vue
特别是带有代理配置的 nginx 设置 - https://github.com/taleodor/mafia-vue/blob/master/nginx/default.conf (请注意,它使用的是 websockets,如果您不使用它们,您可以将其删除)。 特别是 vue 开发服务器配置 -https://github.com/taleodor/mafia-vue/blob/master/vue.config.js 。
写上 CI / CD 工作(与您的问题无关,但可能有用)- https://itnext.io/building-kubernetes-cicd-pipeline-with-github-actions-argocd-and-reliza-hub-e7120b9be870
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.