Home > database >  Kubernetes service URL not responding to API call
Kubernetes service URL not responding to API call

Time:04-06

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?

CodePudding user response:

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
    

CodePudding user response:

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.

  • Related