使用Cookie关联性配置Ingress时出现问题 [英] Problems configuring Ingress with cookie affinity

查看:435
本文介绍了使用Cookie关联性配置Ingress时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找如何使用Ingress在GKE中使用Cookie相似性。

I was looking for how to use cookie affinity in GKE, using Ingress for that.

我找到了以下链接: https://cloud.google.com/kubernetes-engine/docs/如何/配置后端服务

我用以下内容创建了Yaml:

I've created a yaml with the following:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-bsc-deployment
spec:
  selector:
    matchLabels:
      purpose: bsc-config-demo
  replicas: 3
  template:
    metadata:
      labels:
        purpose: bsc-config-demo
    spec:
      containers:
      - name: hello-app-container
        image: gcr.io/google-samples/hello-app:1.0
---
apiVersion: cloud.google.com/v1beta1
kind: BackendConfig
metadata:
  name: my-bsc-backendconfig
spec:
  timeoutSec: 40
  connectionDraining:
    drainingTimeoutSec: 60
  sessionAffinity:
    affinityType: "GENERATED_COOKIE"
    affinityCookieTtlSec: 50
---
apiVersion: v1
kind: Service
metadata:
  name: my-bsc-service
  labels:
    purpose: bsc-config-demo
  annotations:
    beta.cloud.google.com/backend-config: '{"ports": {"80":"my-bsc-backendconfig"}}'
spec:
  type: NodePort
  selector:
    purpose: bsc-config-demo
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-bsc-ingress
spec:
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: my-bsc-service
          servicePort: 80
---

一切似乎都很顺利。检查创建的Ingress时,我会看到2个后端服务。

Everything seems to go well. When I inspect the created Ingress I see 2 backend services. One of them has the cookie configured, but the other doesn't.

如果我创建了部署,并从GCP的控制台中创建了Service and Ingress,则只有一个后端服务出现。

If I create the deployment, and from GCP's console, create the Service and Ingress, only one backend service appears.

有人知道为什么使用Yaml可以得到2,但是从控制台上只能得到一个吗?

Somebody knows why using a yaml I get 2, but doing it from console I only get one?

预先感谢

奥斯卡

推荐答案

您的定义是

有两个后端的原因是因为您的入口未定义默认后端。 GCE LB需要默认后端,因此在创建LB的过程中,会将第二个后端添加到LB中作为默认值(此后端除了提供404响应外不执行任何操作)。默认后端不使用backendConfig。

The reason you have two backend's is because your ingress does not define a default backend. GCE LB require a default backend so during LB creation, a second backend is added to the LB to act as the default (this backend does nothing but serve 404 responses). The default backend does not use the backendConfig.

这应该没问题,但是如果要确保仅使用后端,请在中定义默认后端值通过添加 spec.backend

This shouldn't be a problem, but if you want to ensure only your backend is used, define a default backend value in your ingress definition by adding the spec.backend:


apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-bsc-ingress
spec:
  backend:
    serviceName: my-bsc-service
    servicePort: 80
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: my-bsc-service
          servicePort: 80

但是,就像我说的,您不需要定义它,额外的后端将不会真正即可发挥作用,并且不需要会话亲和力(无论如何只有一个吊舱)。如果您感到好奇,则在kube-system命名空间中,有问题的默认后端容器称为 l7-default-backend- [replicaSet_hash]-[pod_hash]

But, like I said, you don't NEED to define this, the additional backend won't really come into play and no sessions affinity is required (there is only a single pod anyway). If you are curious, the default backend pod in question is called l7-default-backend-[replicaSet_hash]-[pod_hash] in the kube-system namespace

这篇关于使用Cookie关联性配置Ingress时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆