5

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.

3
  • 1
    Not sure if you are intentionally using NodePort? If so see stackoverflow.com/questions/52345855/… It is more normal to either use NodePort or switch to ClusterIP and install an ingress controller and use ingress. If you don't have an ingress controller then I suggest you pick one (e.g. Nginx), install it and use its specific annotations on your ingress. Commented Oct 25, 2018 at 22:09
  • How you make your cluster on GCP? Do you just spin up few VMs and setup Kubernetes manually or you use GKE (Google Kubernetes Engine)?
    – Nick Rak
    Commented Oct 26, 2018 at 13:20
  • @NickRak I use kubernetes Engine
    – Sermanes
    Commented Oct 26, 2018 at 15:23

2 Answers 2

2

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
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.