我有 2 个 Angular 应用程序,它们位于 Minikube 集群上同一(默认)命名空间中的不同 Pod 中。我正在使用模块联合来进行它们之间的通信。
我的yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: host-app
spec:
replicas: 1
selector:
matchLabels:
app: host-app
template:
metadata:
labels:
app: host-app
spec:
containers:
- name: host-app
image: testexampleuser/host-mf-app
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: host-app-srv
spec:
selector:
app: host-app
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: remote-app
spec:
replicas: 1
selector:
matchLabels:
app: remote-app
template:
metadata:
labels:
app: remote-app
spec:
containers:
- name: remote-app
image: testexampleuser/remote-mf-app
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: remote-app-srv
spec:
selector:
app: remote-app
ports:
- protocol: TCP
port: 80
targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: ms.test
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: host-app-srv
port:
number: 80
- path: /todo-list
pathType: Prefix
backend:
service:
name: host-app-srv
port:
number: 80
以及我的主应用程序的 webpack.config.js:
const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const mf = require("@angular-architects/module-federation/webpack");
const path = require("path");
const share = mf.share;
const sharedMappings = new mf.SharedMappings();
sharedMappings.register(
path.join(__dirname, 'tsconfig.json'),
[/* mapped paths to share */]);
module.exports = {
output: {
uniqueName: "hostApp",
publicPath: "auto",
scriptType: "text/javascript"
},
optimization: {
runtimeChunk: false
},
resolve: {
alias: {
...sharedMappings.getAliases(),
}
},
experiments: {
outputModule: true
},
plugins: [
new ModuleFederationPlugin({
name: "hostApp",
remotes: {
remoteApp1: 'remoteApp1@http://remote-app-srv/remoteEntry.js'
},
shared: share({
"@angular/core": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/common": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/common/http": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
"@angular/router": { singleton: true, strictVersion: true, requiredVersion: 'auto' },
...sharedMappings.getDescriptors()
})
}),
sharedMappings.getPlugin()
],
};
在此我将我的网址指定为http://remote-app-srv/remoteEntry.js,因此尝试通过服务名称访问它,但我在控制台中有
GET http://remote-app-srv/remoteEntry.js net::ERR_NAME_NOT_RESOLVED
,这表明它不是能够根据服务名称找到IP。使用服务的完全限定名称时也会发生同样的情况。但是,当在命令提示符中使用 kubectl exec -it remote-app-64b485f7d8-pph7z -- nslookup remote-app-srv
时,我得到
kubectl exec -it remote-app-64b485f7d8-pph7z -- nslookup remote-app-srv
Server: 10.96.0.10
Address: 10.96.0.10:53
Name: remote-app-srv.default.svc.cluster.local
Address: 10.99.114.182
** server can't find remote-app-srv.cluster.local: NXDOMAIN
** server can't find remote-app-srv.cluster.local: NXDOMAIN
** server can't find remote-app-srv.svc.cluster.local: NXDOMAIN
** server can't find remote-app-srv.svc.cluster.local: NXDOMAIN
command terminated with exit code 1
看来,它解析正确,但是当在应用程序中使用服务名称时,它无法找到该IP。导致此问题的原因是什么?
更新:当我修改入口并包含 /remoteEntry.js 作为路径时,该路径然后转发到我的远程服务,并将我的 url 修改为: http://ms.test/remoteEntry.js 然后在我有控制台:
remoteEntry.js:1 GET http://ms.test/487.a4d1c1bd4d8ce404.js net::ERR_ABORTED 404 (Not Found)
__webpack_require__.l @ remoteEntry.js:1
__webpack_require__.f.j @ remoteEntry.js:1
(anonymous) @ remoteEntry.js:1
__webpack_require__.e @ remoteEntry.js:1
./TodoListModule @ remoteEntry.js:1
g @ remoteEntry.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
T @ 268.4135e908b4fc6bc1.js:1
g @ 268.4135e908b4fc6bc1.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
e @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
F @ 268.4135e908b4fc6bc1.js:1
q @ 268.4135e908b4fc6bc1.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
T @ 268.4135e908b4fc6bc1.js:1
g @ 268.4135e908b4fc6bc1.js:1
invoke @ polyfills.fe9dcec8806eea43.js:1
onInvoke @ 256.612799c9aae468e4.js:1
invoke @ polyfills.fe9dcec8806eea43.js:1
run @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ polyfills.fe9dcec8806eea43.js:1
invokeTask @ polyfills.fe9dcec8806eea43.js:1
onInvokeTask @ 256.612799c9aae468e4.js:1
invokeTask @ polyfills.fe9dcec8806eea43.js:1
runTask @ polyfills.fe9dcec8806eea43.js:1
y @ polyfills.fe9dcec8806eea43.js:1
invokeTask @ polyfills.fe9dcec8806eea43.js:1
U @ polyfills.fe9dcec8806eea43.js:1
W @ polyfills.fe9dcec8806eea43.js:1
ue @ polyfills.fe9dcec8806eea43.js:1
load (async)
e @ polyfills.fe9dcec8806eea43.js:1
scheduleTask @ polyfills.fe9dcec8806eea43.js:1
onScheduleTask @ polyfills.fe9dcec8806eea43.js:1
scheduleTask @ polyfills.fe9dcec8806eea43.js:1
scheduleTask @ polyfills.fe9dcec8806eea43.js:1
scheduleEventTask @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ polyfills.fe9dcec8806eea43.js:1
o.set @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
e @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
T @ 268.4135e908b4fc6bc1.js:1
g @ 268.4135e908b4fc6bc1.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
e @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
A @ 268.4135e908b4fc6bc1.js:1
O @ 268.4135e908b4fc6bc1.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
T @ 268.4135e908b4fc6bc1.js:1
g @ 268.4135e908b4fc6bc1.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
e @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
I @ 268.4135e908b4fc6bc1.js:1
D @ 268.4135e908b4fc6bc1.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
T @ 268.4135e908b4fc6bc1.js:1
g @ 268.4135e908b4fc6bc1.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
e @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ 268.4135e908b4fc6bc1.js:1
P @ 268.4135e908b4fc6bc1.js:1
Y @ 268.4135e908b4fc6bc1.js:1
loadChildren @ 268.4135e908b4fc6bc1.js:1
loadModuleFactoryOrRoutes @ 384.caca277fba7706c5.js:1
loadChildren @ 384.caca277fba7706c5.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
Z @ 256.612799c9aae468e4.js:1
x @ 256.612799c9aae468e4.js:1
F._next @ 256.612799c9aae468e4.js:1
next @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
_trySubscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
X @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
X @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
e.subscribe.s @ 384.caca277fba7706c5.js:1
F._next @ 256.612799c9aae468e4.js:1
next @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F._next @ 256.612799c9aae468e4.js:1
next @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
_trySubscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
Z @ 256.612799c9aae468e4.js:1
x @ 256.612799c9aae468e4.js:1
F._next @ 256.612799c9aae468e4.js:1
next @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
_trySubscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
X @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
Z @ 256.612799c9aae468e4.js:1
x @ 256.612799c9aae468e4.js:1
F._next @ 256.612799c9aae468e4.js:1
next @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
_trySubscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
X @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 384.caca277fba7706c5.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
F @ 256.612799c9aae468e4.js:1
subscribe @ 256.612799c9aae468e4.js:1
e.subscribe.s @ 384.caca277fba7706c5.js:1
F._next @ 256.612799c9aae468e4.js:1
next @ 256.612799c9aae468e4.js:1
subscribe.i @ 384.caca277fba7706c5.js:1
F._next @ 256.612799c9aae468e4.js:1
next @ 256.612799c9aae468e4.js:1
(anonymous) @ 256.612799c9aae468e4.js:1
invoke @ polyfills.fe9dcec8806eea43.js:1
onInvoke @ 256.612799c9aae468e4.js:1
invoke @ polyfills.fe9dcec8806eea43.js:1
run @ polyfills.fe9dcec8806eea43.js:1
(anonymous) @ polyfills.fe9dcec8806eea43.js:1
invokeTask @ polyfills.fe9dcec8806eea43.js:1
onInvokeTask @ 256.612799c9aae468e4.js:1
invokeTask @ polyfills.fe9dcec8806eea43.js:1
runTask @ polyfills.fe9dcec8806eea43.js:1
y @ polyfills.fe9dcec8806eea43.js:1
invokeTask @ polyfills.fe9dcec8806eea43.js:1
U @ polyfills.fe9dcec8806eea43.js:1
W @ polyfills.fe9dcec8806eea43.js:1
ue @ polyfills.fe9dcec8806eea43.js:1
268.4135e908b4fc6bc1.js:1 ChunkLoadError: Loading chunk 487 failed.
(error: http://ms.test/487.a4d1c1bd4d8ce404.js)
at __webpack_require__.f.j (remoteEntry.js:1:7277)
at remoteEntry.js:1:1216
at Array.reduce (<anonymous>)
at __webpack_require__.e (remoteEntry.js:1:1177)
at ./TodoListModule (remoteEntry.js:1:83)
at Object.g (remoteEntry.js:1:143)
at 268.4135e908b4fc6bc1.js:1:528
at Generator.next (<anonymous>)
at T (268.4135e908b4fc6bc1.js:1:163)
at g (268.4135e908b4fc6bc1.js:1:365)
256.612799c9aae468e4.js:1 ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'ɵmod')
TypeError: Cannot read properties of undefined (reading 'ɵmod')
at Xe (256.612799c9aae468e4.js:1:31475)
at new Xa (256.612799c9aae468e4.js:1:136284)
at Xo.create (256.612799c9aae468e4.js:1:136822)
at 384.caca277fba7706c5.js:1:79337
at 256.612799c9aae468e4.js:1:10630
at F._next (256.612799c9aae468e4.js:1:10079)
at F.next (256.612799c9aae468e4.js:1:3860)
at Z.subscribe._ (256.612799c9aae468e4.js:1:11217)
at F._next (256.612799c9aae468e4.js:1:10079)
at F.next (256.612799c9aae468e4.js:1:3860)
at ye (polyfills.fe9dcec8806eea43.js:1:16009)
at ye (polyfills.fe9dcec8806eea43.js:1:15548)
at polyfills.fe9dcec8806eea43.js:1:16854
at N.invokeTask (polyfills.fe9dcec8806eea43.js:1:7153)
at Object.onInvokeTask (256.612799c9aae468e4.js:1:170779)
at N.invokeTask (polyfills.fe9dcec8806eea43.js:1:7074)
at z.runTask (polyfills.fe9dcec8806eea43.js:1:2495)
at y (polyfills.fe9dcec8806eea43.js:1:9194)
at P.invokeTask [as invoke] (polyfills.fe9dcec8806eea43.js:1:8237)
at U (polyfills.fe9dcec8806eea43.js:1:20912)
我觉得很奇怪,因为当我进入 Pod 内部时,我可以清楚地看到该文件可用,而且,我什至能够访问 http://ms.test/remoteEntry.js 的内容浏览器,只是在应用程序中使用时不起作用。
当您使用
Ingress
时,您不应使用服务来访问您的应用程序。首先,您需要将 ms.test
解析为您的 minikube ip,然后尝试您在 Ingress yaml 文件中设置的路径。例如,你应该尝试这个:
GET http://ms.test/
当您点击
/
路径时,它会调用 host-app-srv
。
希望有帮助!