'Kubernetes service URL not responding to API call

I've been following multiple tutorials on how to deploy my (Spring Boot) api on Minikube. I already got it (user-service running on 8081) working in a docker container with an api gateway (port 8080) and eureka (port 8087), but for starters I just want it to run without those. Steps I took:

  1. Push docker container or image (?) to docker hub, I don't know the proper term.

  2. Create a deployment.yaml:

    apiVersion: v1
    kind: Service
    metadata:
      name: kwetter-service
    spec:
      type: LoadBalancer
      selector:
        app: kwetter
      ports:
        - protocol: TCP
          port: 8080
          targetPort: 8081
          nodePort: 30070
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: kwetter-deployment
      labels:
        app: kwetter
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: kwetter
      template:
        metadata:
          labels:
            app: kwetter
        spec:
          containers:
            - name: user-api
              image: cazhero/s6-kwetter-backend_user:latest
              ports: 
                - containerPort: 8081 #is the port it runs on when I manually start it up
    
  3. kubectl apply -f deployment.yaml

  4. minikube service kwetter-service

  5. It takes me to an empty site with url: http://192.168.49.2:30070 which I thought I could use to make API calls to, but apparently not. How do I make api calls to my application running on minikube?

Get svc returns:

NAME              TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
kubernetes        ClusterIP      10.96.0.1      <none>        443/TCP          4d4h
kwetter-service   LoadBalancer   10.106.42.56   <pending>     8080:30070/TCP   4d

describe svc kwetter-service:

Name:                     kwetter-service
Namespace:                default
Labels:                   <none>
Annotations:              <none>
Selector:                 app=kwetter
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
IP:                       10.106.42.56
IPs:                      10.106.42.56
Port:                     <unset>  8080/TCP
TargetPort:               8081/TCP
NodePort:                 <unset>  30070/TCP
Endpoints:                172.17.0.4:8081
Session Affinity:         None
External Traffic Policy:  Cluster
Events:
  Type    Reason  Age   From                Message
  ----    ------  ----  ----                -------
  Normal  Type    6s    service-controller  LoadBalancer -> NodePort

Made an Ingress in the yaml, used kubectl get ing:

NAME              CLASS    HOSTS   ADDRESS   PORTS   AGE
kwetter-ingress   <none>   *                 80      49m


Solution 1:[1]

To make some things clear:

  1. You need to have pushed your docker image cazhero/s6-kwetter-backend_user:latest to docker hub, check that at https://hub.docker.com/, in your personal repository.
  2. What's the output of minikube service kwetter-service, does it print the URL http://192.168.49.2:30070?
  3. Make sure your pod is running correctly by the following minikube command:
    # check pod status
    minikube kubectl -- get pods
    # if the pod is running, check its container logs
    minikube kubectl -- logs po kwetter-deployment-xxxx-xxxx
    

Solution 2:[2]

I see that you are using LoadBalancer service, where a LoadBalancer service is the standard way to expose a service to the internet. With this method, each service gets its own IP address.

  • Check external IP

    kubectl get svc
    
  • Use the external IP and the port number in this format to access the application.

    http://REPLACE_WITH_EXTERNAL_IP:8080
    

If you want to access the application using Nodeport (30070), use the Nodeport service instead of LoadBalancer service.

Refer to this documentation for more information on accessing applications through Nodeport and LoadBalancer services.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2