Matteo Tosato
Matteo Tosato

Reputation: 235

Kubernetes - Ingress v1

I have some troubles to setup an ingress resource on top of a GKE cluster. I'm having a 404 error response on any type of HTTP requests. The following are my deployment, service and ingress configurations:

Deployment and service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: snap-api
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: snap-api
  template:
    metadata:
      labels:
        app: snap-api
    spec:
      serviceAccountName: snap-ksa
      containers:
      - image: eu.gcr.io/snap-xxx/services/snap-api:latest
        imagePullPolicy: Always
        name: snap-api
        ports:
        - containerPort: 5001
          protocol: TCP
        resources:
          requests:
            memory: "200Mi"
            cpu: "200m"
          limits:
            memory: "1Gi"
            cpu: "1"            
        env:
          - name: ASPNETCORE_ENVIRONMENT
            value: Production
          - name: CONFIG_CONNECTION_STRING
            valueFrom:
              secretKeyRef:
                name: snap-secrets
                key: config_connection_string
          - name: DATA_CONNECTION_STRING
            valueFrom:
              secretKeyRef:
                name: snap-secrets
                key: data_connection_string
          # TODO: Dev cert               
          - name: TLS_KEY_PATH
            value: /app/aspnetapp.pfx
          - name: TLS_KEY_PASSPHRASE
            valueFrom:
              secretKeyRef:
                name: snap-secrets
                key: tls_key_passphrase   
      - name: cloud-sql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:1.17
        command:
          - "/cloud_sql_proxy"
          - "-instances=snap-xxx:europe-west1:snap-tenant-db=tcp:1433"
        securityContext:
          runAsNonRoot: true
        ports:
        - containerPort: 1433
          protocol: TCP          
        resources:
          requests:
            memory: "500Mi"
            cpu: "1"
          limits:
            memory: "2Gi"
            cpu: "1"                 
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: snap-api-service
  namespace: default
spec:
  type: NodePort
  selector:
    app: snap-api
  ports:
    - targetPort: 5001
      name: http
      protocol: TCP
      port: 60000

And the ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: snap-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
    - http:
        paths:
        - pathType: Prefix
          path: /api/*
          backend:
            service:
              name: snap-api-service
              port: 
                number: 60000

I was wondering that can by a firewall problem? Also healt checks are failing on my service... The following is the output of "kubectl describe ingress snap-ingress" command:

Name:             snap-ingress
Namespace:        default
Address:          x.x.x.x
Default backend:  default-http-backend:80 (10.6.0.2:8080)
Rules:
  Host        Path  Backends
  ----        ----  --------
  *
              /api/*   snap-api-service:60000 (10.6.0.130:5001)
Annotations:  ingress.kubernetes.io/backends:
                {"k8s-be-31084--19bd63f37342a0f0":"HEALTHY","k8s1-19bd63f3-default-snap-api-service-60000-d79961e6":"UNHEALTHY"}
              ingress.kubernetes.io/forwarding-rule: k8s2-fr-2zv080r1-default-snap-ingress-4rmjay2y
              ingress.kubernetes.io/target-proxy: k8s2-tp-2zv080r1-default-snap-ingress-4rmjay2y
              ingress.kubernetes.io/url-map: k8s2-um-2zv080r1-default-snap-ingress-4rmjay2y
              nginx.ingress.kubernetes.io/rewrite-target: /
  Type    Reason     Age                   From                     Message
  ----    ------     ----                  ----                     -------
  Normal  Sync       7m18s                 loadbalancer-controller  UrlMap "k8s2-um-2zv080r1-default-snap-ingress-4rmjay2y" created
  Normal  Sync       7m16s                 loadbalancer-controller  TargetProxy "k8s2-tp-2zv080r1-default-snap-ingress-4rmjay2y" created
  Normal  Sync       7m6s                  loadbalancer-controller  ForwardingRule "k8s2-fr-2zv080r1-default-snap-ingress-4rmjay2y" created
  Normal  IPChanged  7m6s                  loadbalancer-controller  IP is now x.x.x.x
  Normal  Sync       112s (x6 over 8m50s)  loadbalancer-controller  Scheduled for sync

Upvotes: 0

Views: 232

Answers (1)

Matteo Tosato
Matteo Tosato

Reputation: 235

After a few days it seems to have been decisive to implement the health check on the Web Api application at the url: "/". After this change, it began to work.

Upvotes: 1

Related Questions