I can't connect my ingress with my service

10/25/2018

I have a problem with my ingress and my service, I can not get that when I connect to the IP of my server, I redirect to the service I have associated with port 80, which is my website. I pass you the configuration files and the description of the ingress:

apiVersion: v1
kind: Namespace
metadata:
  name: bookstack
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    service: mysql
  name: mysql
  namespace: bookstack
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        service: mysql
    spec:
      containers:
      - env:
        - name: MYSQL_DATABASE
          value: bookstack
        - name: MYSQL_PASS
          value: pass
        - name: MYSQL_ROOT_PASSWORD
          value: root
        - name: MYSQL_USER
          value: user
        image: mysql:5.7
        name: mysql
        ports:
        - containerPort: 3306
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  labels:
    service: mysql
  name: mysql
  namespace: bookstack
spec:
  type: NodePort
  ports:
  - name: "3306"
    port: 3306
    targetPort: 3306
  selector:
    service: mysql
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: bookstack
  name: bookstack
  namespace: bookstack
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: bookstack
    spec:
      containers:
      - env:
        - name: namespace
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: podname
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: nodename
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: DB_DATABASE
          value: bookstack
        - name: DB_HOST
          value: mysql
        - name: DB_PASSWORD
          value: root
        - name: DB_USERNAME
          value: root
        image: solidnerd/bookstack:latest
        name: bookstack
        ports:
        - name: http
          containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  labels:
    app: bookstack
  name: bookstack
  namespace: bookstack
spec:
  type: NodePort
  ports:
  - name: http-port
    port: 80
    protocol: TCP
  selector:
    app: bookstack
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: http
  namespace: bookstack
spec:
  backend:
    serviceName: bookstack
    servicePort: http-port

This is what appears on my ingress:

Name:             http
Namespace:        bookstack
Address:
Default backend:  bookstack:http-port (10.36.0.22:80)
Rules:
  Host  Path  Backends
  ----  ----  --------
  *     *     bookstack:http-port (10.36.0.22:80)
Annotations:
  kubectl.kubernetes.io/last-applied-configuration:  {"apiVersion":"extensions/v1beta1","kind":"Ingress","metadata":{"annotations":{},"name":"http","namespace":"bookstack"},"spec":{"backend":{"serviceName":"bookstack","servicePort":"http-port"}}}

Events:  <none>

It doesn't return any external IP to connect me, why could it be? I want to avoid using LoadBalancer as a service type.

-- Sermanes
google-cloud-platform
kubernetes

2 Answers

10/25/2018

There wouldn't be an external IP specifically because NodePort represents all the nodes on your cluster on that specific port. So, essentially you would have to point an external load balancer or that traffic source to each of the nodes on your cluster on that specific NodePort.

Note that if you are using ExternalTrafficPolicy=Local only the nodes that have pods for your service will reply.

-- Rico
Source: StackOverflow

10/30/2018

The main problem was that I didn't have activated the balancer that Google Kubernetes Engine offers by default, not having it active I couldn't generate an external ip because there wasn't a balancer. There are two solutions, either activate GKE's default load balancer or create a type of service: LoadBalancer.

Important to activate also within the deploy the readinessProbe and livenessProbe.

An example:

    readinessProbe:
      httpGet:
        path: /login
        port: 80
      initialDelaySeconds: 5
      timeoutSeconds: 1
      periodSeconds: 15
    livenessProbe:
      httpGet:
        path: /login
        port: 80
      initialDelaySeconds: 15
      timeoutSeconds: 1
      periodSeconds: 15
-- Sermanes
Source: StackOverflow