ccd*_*ccd 2 kubernetes kubernetes-ingress
我配置的入口与控制器 ingress-nginx 一起运行。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
tls:
- hosts:
- XXX.XX.com
secretName: app-tls
rules:
- host: XXX.XX.com
http:
paths:
- path: /my-api(/|$)(.*)
backend:
serviceName: app
servicePort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-api
spec:
selector:
app: my-api
ports:
- name: app
port: 3000
targetPort: 3000
Run Code Online (Sandbox Code Playgroud)
我可以在本地运行 api curl localIP:3000/testapi,但它不能远程运行。
# kubectl describe ingress app-ingress
Name: app-ingress
Namespace: default
Address: XX.XX.XX.XX
Default backend: default-http-backend:80 (<error: endpoints "default-http-backend" not found>)
TLS:
app-tls terminates www.daichenchen.cn
Rules:
Host Path Backends
---- ---- --------
XXX.XX.com
/my-api(/|$)(.*) app:80 (<error: endpoints "app" not found>)
Run Code Online (Sandbox Code Playgroud)
我已经成功安装了 ingress-nginx 并且所有的 pod 都没有错误地工作。
您serviceName在Ingress规则中定义并且Service应该相同。
像这样 :
...
rules:
- host: XXX.XX.com
http:
paths:
- path: /my-api(/|$)(.*)
backend:
serviceName: app
servicePort: 80
Run Code Online (Sandbox Code Playgroud)
apiVersion: v1
kind: Service
metadata:
name: app
spec:
selector:
app: my-api
ports:
- name: app
port: 3000
targetPort: 3000
Run Code Online (Sandbox Code Playgroud)
如果Ingress和Service位于不同的命名空间,您还可以将服务名称添加到入口规则中。在这种情况下,您需要为 service 使用 dns 名称<service-name>.<namespace>。
例如:
rules:
- host: example.com
http:
paths:
- path: /my-api
backend:
serviceName: test-service.test-namespace
servicePort: 80
Run Code Online (Sandbox Code Playgroud)
apiVersion: v1
kind: Service
metadata:
name: test-service
namespace: test-namespace
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6193 次 |
| 最近记录: |