tiago arruda
tiago arruda

Reputation: 3

Cant configure ingress on gcloud properly

I am trying to deploy a simple app on google cloud. I am testing the gitlab kluster integration. Here is my yaml k8:

---
apiVersion: v1
kind: Service
metadata:
  name: service
  namespace: "my-service"
  labels:
    run: service
spec:
  type: NodePort
  selector:
    run: "service"
  ports:
  - port: 9000
    targetPort: 9000
    protocol: TCP
    name: http

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: service-api
  namespace: "my-service"
  labels:
    run: service

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-v1
  namespace: "my-service"
  labels:
    run: service
spec:
  replicas: 1
  selector:
    matchLabels:
      run: service
  template:
    metadata:
      labels:
        run: service
    spec:
      serviceAccountName: service-api
      containers:
        - name: service
          image: "gcr.io/test/service:latest"
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9000
              protocol: TCP
          volumeMounts:
            - name: test
              mountPath: /usr/test
      volumes:
        - name: test
          emptyDir: {}

---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: "service-ingress"
  namespace: "my-service"
  labels:
    run: service
spec:
  rules:
  - http:
      paths:
      - path: /*
        backend:
          serviceName: service
          servicePort: 9000

If I log into the pod I can curl the service on the nodePort designed IP, but if I try to hit the ingress address I just get a error:

I am not sure why there are 2 backend services on the loadbalancer that is created automatically, the one that points to my app shows as unhealthy

[load balancer backends1

Upvotes: 0

Views: 61

Answers (1)

Arghya Sadhu
Arghya Sadhu

Reputation: 44687

You need to define readiness probe in your pod spec because GKE ingress controller picks up health check from the readiness probe.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: service-v1
  namespace: "my-service"
  labels:
    run: service
spec:
  replicas: 1
  selector:
    matchLabels:
      run: service
  template:
    metadata:
      labels:
        run: service
    spec:
      serviceAccountName: service-api
      containers:
        - name: service
          image: "gcr.io/test/service:latest"
          imagePullPolicy: IfNotPresent
          readinessProbe:
            httpGet:
              path: /healthz
              port: 8080
            initialDelaySeconds: 3
            periodSeconds: 3
          ports:
            - containerPort: 9000
              protocol: TCP
          volumeMounts:
            - name: test
              mountPath: /usr/test
      volumes:
        - name: test
          emptyDir: {}

Upvotes: 1

Related Questions