我正在尝试为当前的Kubernetes体系结构配置一个额外的Sticky Session层。我不想通过主LoadBalancer服务路由每个请求,而是想通过nginx粘性会话的上层路由请求。我正在遵循https://kubernetes.github.io/ingress-nginx/examples/affinity/cookie/
上的指南我将Azure云用于群集部署。以前,使用具有LoadBalancer类型的服务会自动生成一个外部IP地址,供用户连接到我的群集。现在,我需要配置静态IP地址以供用户连接,并设置好nginx入口。我该怎么办?我在这里遵循了指南-https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/static-ip,但是Ingress的外部地址仍然为空!
我做错了什么?
# nginx-sticky-service.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress-lb
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
externalTrafficPolicy: Local
type: LoadBalancer
ports:
- port: 80
name: http
targetPort: 80
- port: 443
name: https
targetPort: 443
selector:
# Selects nginx-ingress-controller pods
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
# nginx-sticky-controller.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-ingress-controller
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
template:
metadata:
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
spec:
terminationGracePeriodSeconds: 60
containers:
- image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.31.0
name: nginx-ingress-controller
ports:
- containerPort: 80
hostPort: 80
- containerPort: 443
hostPort: 443
resources:
limits:
cpu: 0.5
memory: "0.5Gi"
requests:
cpu: 0.5
memory: "0.5Gi"
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
args:
- /nginx-ingress-controller
- --publish-service=$(POD_NAMESPACE)/nginx-ingress-lb
# nginx-sticky-server.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-nginx
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/affinity: "cookie"
nginx.ingress.kubernetes.io/session-cookie-name: "nginx-sticky-server"
nginx.ingress.kubernetes.io/session-cookie-expires: "172800"
nginx.ingress.kubernetes.io/session-cookie-max-age: "172800"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/affinity-mode: persistent
nginx.ingress.kubernetes.io/session-cookie-hash: sha1
spec:
rules:
- http:
paths:
- backend:
# This assumes http-svc exists and routes to healthy endpoints.
serviceName: my-own-service-master
servicePort: http
答案 0 :(得分:0)
好,我知道了。我认为区别在于您使用的云提供商,对于Azure Cloud,您应该遵循他们的文档以及他们在Kubernetes群集中实现入口控制器的方式。
通过here进行链接以部署入口控制器。他们在Kubernetes集群中创建公共IP地址并将其与入口控制器链接的方式有效。我可以确定截至目前的写作时间。
完成上面链接中的步骤后,我可以照常应用ingress .yaml文件,即kubectl apply -f nginx-sticky-server.yaml
来设置nginx粘性会话。如果您在入口.yaml文件中指定的服务名称和服务端口正确,则nginx入口控制器应将您的用户请求重定向到正确的服务。