Canot access to sidecar container in Kubernetes

8/31/2018

I have the following hello world deployment.

---
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

And I have ingress object deploy with side-car container

---
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

And I have Ingress here

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

I would expect to access to /alb-sidecar the same way that I access to /hello, but only /hello endpoint works for me. And keep getting 502 Bad Gateway for /alb-sidecar endpoint. The sidecar container is just a simple web app listening on /alb-sidecar.

Do I need do anything different when the sidecar container runs in a different namespace or how would you run a sidecar next to ALB ingress controller?

-- enerudfwqenq
aws-elb
kubernetes

1 Answer

9/1/2018

If you created the deployment alb-ingress-controller and the service alb-ingress-controller-service in another namespace, you need to create another ingress resource in the exact namespace.

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
-- Luminance
Source: StackOverflow