0

我有以下 hello world 部署。

---
apiVersion: extensions/v1beta1
kind: Deployment

metadata:
name: hello-deployment

spec:
replicas: 1

template:
    metadata:
    labels:
        app: hello
    spec:
    containers:
    - name: hello
        image: hello:v0.0.1
        imagePullPolicy: Always
        args:
        - /hello
        ports:
        - containerPort: 3000

---
apiVersion: v1
kind: Service

metadata:
name: hello-service

spec:
ports:
- port: 80
    targetPort: 3000
    protocol: TCP

selector:
    app: hello
type: NodePort

我有入口对象部署与边车容器

---
apiVersion: extensions/v1beta1
kind: Deployment

metadata:
labels:
    app: alb-ingress-controller
name: alb-ingress-controller
namespace: kube-system

spec:
replicas: 1

selector:
    matchLabels:
    app: alb-ingress-controller

template:
    metadata:
    creationTimestamp: null
    labels:
        app: alb-ingress-controller
    spec:
    containers:
    - name: server
        image: alb-ingress-controller:v0.0.1
        imagePullPolicy: Always
        args:
        - /server
        - --ingress-class=alb
        - --cluster-name=AAA
        - --aws-max-retries=20
        - --healthz-port=10254

        ports:
        - containerPort: 10254
        protocol: TCP

    - name: alb-sidecar
        image: sidecar:v0.0.1
        imagePullPolicy: Always
        args:
        - /sidecar
        - --port=5000
        ports:
        - containerPort: 5000
        protocol: TCP

    dnsPolicy: ClusterFirst
    restartPolicy: Always
    securityContext: {}
    terminationGracePeriodSeconds: 30
    serviceAccountName: alb-ingress
    serviceAccount: alb-ingress

---
apiVersion: v1
kind: Service

metadata:
name: alb-ingress-controller-service

spec:
ports:
- port: 80
    targetPort: 5000
    protocol: TCP

selector:
    app: alb-ingress-controller
type: NodePort

我在这里有 Ingress

apiVersion: extensions/v1beta1
kind: Ingress

metadata:
name: test-alb
annotations:
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80,"HTTPS": 443}]'
    alb.ingress.kubernetes.io/subnets: AAA
    alb.ingress.kubernetes.io/security-groups: AAA
labels:
    app: test-alb

spec:
rules:
- http:
    paths:
    - path: /hello
        backend:
        serviceName: hello-service
        servicePort: 80
    - path: /alb-sidecar
        backend:
        serviceName: alb-ingress-controller-service
        servicePort: 80

我希望以与访问/alb-sidecar相同的方式访问/hello,但只有/hello端点对我有用。并继续获取502 Bad Gateway端点/alb-sidecar。Sidecar 容器只是一个简单的 Web 应用程序监听/alb-sidecar.

当 sidecar 容器在不同的命名空间中运行时,我是否需要做任何不同的事情,或者您将如何在 ALB 入口控制器旁边运行 sidecar?

4

1 回答 1

1

如果您在另一个命名空间中创建了部署alb-ingress-controller和服务alb-ingress-controller-service,则需要在确切的命名空间中创建另一个入口资源。

apiVersion: extensions/v1beta1
kind: Ingress

metadata:
name: test-alb
namespace: alb-namespace
annotations:
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP":80,"HTTPS": 443}]'
    alb.ingress.kubernetes.io/subnets: AAA
    alb.ingress.kubernetes.io/security-groups: AAA
labels:
    app: alb-service

spec:
rules:
- http:
    paths:
    - path: /alb-sidecar
        backend:
        serviceName: alb-ingress-controller-service
        servicePort: 80
于 2018-09-01T09:36:54.990 回答