Kubernetes 路由到特定 pod 的功能是 url 中的参数



我需要的东西看起来像这样:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
name: http
spec:
serviceName: "nginx-set"
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: gcr.io/google_containers/nginx-slim:0.8
ports:
- containerPort: 80
name: http
----
apiVersion: v1
kind: Service
metadata:
name: nginx-set
labels:
app: nginx
spec:
ports:
- port: 80
name: http
clusterIP: None
selector:
app: nginx

这是有趣的部分:

apiVersion: voyager.appscode.com/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
spec:
rules:
- host: appscode.example.com
http:
paths:
- path: '/testPath'
backend:
hostNames:
- web-0
serviceName: nginx-set #! There is no extra service. This
servicePort: '80'      # is the Statefulset's Headless Service

由于在 url 的功能中设置了主机名,我能够定位特定的 pod。

现在我想知道是否有可能在 kubernetes 中创建这样的规则

apiVersion: voyager.appscode.com/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
spec:
rules:
- host: appscode.example.com
http:
paths:
- path: '/connect/(d+)'
backend:
hostNames:
- web-(result of regex match with d+)
serviceName: nginx-set #! There is no extra service. This
servicePort: '80'      # is the Statefulset's Headless Service

或者如果我必须为每个 pod 编写一个规则?

抱歉,这是不可能的,最好的解决方案是创建多个路径,每个路径引用一个 pod:

apiVersion: voyager.appscode.com/v1beta1
kind: Ingress
metadata:
name: test-ingress
namespace: default
spec:
rules:
- host: appscode.example.com
http:
paths:
- path: '/connect/0'
backend:
hostNames:
- web-0
serviceName: nginx-set
servicePort: '80'
- path: '/connect/1'
backend:
hostNames:
- web-1
serviceName: nginx-set
servicePort: '80'

最新更新