作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用minikube在Kubernetes上部署我的微服务应用程序。我有一个 Angular 前台服务和两个后端服务,我使用此配置进行午餐部署和服务
apiVersion: apps/v1
kind: Deployment
metadata:
name: searchservice
labels:
app: searchservice
spec:
selector:
matchLabels:
app: searchservice
template:
metadata:
labels:
app: searchservice
spec:
containers:
- name: searchservice
image: ayoubdali/searchservice:0.1.9-SNAPSHOT
ports:
- containerPort: 8070
---
apiVersion: v1
kind: Service
metadata:
name: searchservice
spec:
type: NodePort
selector:
app: searchservice
ports:
- protocol: TCP
# Port accessible inside cluster
port: 8070
# Port to forward to inside the pod
targetPort: 8070
nodePort: 31000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: searchappfront
labels:
app: searchappfront
spec:
selector:
matchLabels:
app: searchappfront
template:
metadata:
labels:
app: searchappfront
spec:
containers:
- name: searchappfront
image: ayoubdali/searchappfront:0.6.5
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: searchappfront
spec:
type: NodePort
selector:
app: searchappfront
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 80
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: subscriberservice
labels:
app: subscriberservice
spec:
selector:
matchLabels:
app: subscriberservice
template:
metadata:
labels:
app: subscriberservice
spec:
containers:
- name: subscriberservice
image: ayoubdali/subscriber-service:0.1.0-SNAPSHOT
ports:
- containerPort: 8090
---
apiVersion: v1
kind: Service
metadata:
name: subscriberservice
spec:
type: NodePort
selector:
app: subscriberservice
ports:
- protocol: TCP
port: 8090
#targetPort: 80
nodePort: 31102
apiVersion: networking.k8s.io/v1beta1 # for versions before 1.14 use extensions/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
rules:
- host: app.info
http:
paths:
- path: /
backend:
serviceName: searchappfront
servicePort: 80
- path: /api
backend:
serviceName: subscriberservice
servicePort: 8090
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
最佳答案
启用 rewrite-target
时,它将创建一个捕获组并将其发送到适当的服务。
如果将捕获组设置为$1
,则将删除根/
之后的所有内容,并将请求转发到根path
。
rewrite-target
行,您的Ingress应该像这样:apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: app.info
http:
paths:
- path: /
backend:
serviceName: searchappfront
servicePort: 80
- path: /api
backend:
serviceName: subscriberservice
servicePort: 8090
echo-apps
来回显请求,我抑制了输出以在后台显示路径和处理它的Pod。echo1-app
正在模拟searchappfront
echo2-app
正在模拟subscriberservice
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: echo-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: app.info
http:
paths:
- path: /
backend:
serviceName: echo1-svc
servicePort: 80
- path: /api
backend:
serviceName: echo2-svc
servicePort: 80
$ kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
echo-ingress app.info 35.188.7.149 80 73m
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
echo1-deploy-764d5df7cf-2wx4m 1/1 Running 0 74m
echo2-deploy-7bcb8f8d5f-xlknt 1/1 Running 0 74m
$ tail -n 1 /etc/hosts
35.188.7.149 app.info
$ curl app.info
{"path": "/",
"os": {"hostname": "echo1-deploy-764d5df7cf-2wx4m"}}
$ curl app.info/foo/bar
{"path": "/foo/bar",
"os": {"hostname": "echo1-deploy-764d5df7cf-2wx4m"}}
$ curl app.info/api
{"path": "/api",
"os": {"hostname": "echo2-deploy-7bcb8f8d5f-xlknt"}}
$ curl app.info/api/foo
{"path": "/api/foo",
"os": {"hostname": "echo2-deploy-7bcb8f8d5f-xlknt"}}
$ curl app.info/api/foo/bar
{"path": "/api/foo/bar",
"os": {"hostname": "echo2-deploy-7bcb8f8d5f-xlknt"}}
echo1-app
echo1-app
echo2-app
echo2-app
NodePort
测试访问权限,但是如果您希望关闭该访问权限,则可以将服务设置为ClusterIP
,因为它将是Ingress来处理传入流量。 searchappfront
将其设置为80
,它将被忽略并且将分配正确的端口。 关于angular - Nginx和Kubernetes背后的黑 Angular 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61859849/
我正在寻找匹配 /(?=\W)(gimme)(?=\W)/gi 或类似的东西。 \W 应该是零宽度字符来包围我的实际匹配项。 也许有一些背景。我想用添加的文字填充替换某些单词(总是 \w+),但前提是
如何在不使用 Intent 连接到 VPN 服务的情况下以编程方式检测流量是否正在通过 VPN。有系统调用吗? 最佳答案 这个有效: private boolean checkVPN() {
我是一名优秀的程序员,十分优秀!