0

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
zhrgci
  • 584
  • 1
  • 6
  • 25
  • If the answer was useful, please upvote or mark the answer as accepted for greater visibility for community members. – Goli Nikitha Apr 20 '22 at 04:54

2 Answers2

0

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
    
YwH
  • 1,050
  • 5
  • 11
  • It doesn't print out anything, it just opens the brower and goes to `http://192.168.49.2:30070`. Pod is running, can't execute the last line though.. – zhrgci Apr 06 '22 at 12:40
  • @Zheng-rongCai did your try to run the last line in a new comand line console? – YwH Apr 06 '22 at 15:21
  • `po` just doesn't exist – zhrgci Apr 06 '22 at 18:51
  • @Zheng-rongCai you should find the pod name matching the `kwetter-deployment-xxxx-xxxx` pattern, and replace the xxxx with your real string. – YwH Apr 07 '22 at 03:23
0

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.

Goli Nikitha
  • 858
  • 3
  • 9
  • Oh well...when I do get svc, the LoadBalancer says: `kwetter-service LoadBalancer 10.106.42.56 8080:30070/TCP 4d` I'll make an edit in the post for better formatting. – zhrgci Apr 06 '22 at 12:41
  • I see that external IP is still in pending state, try using this command `kubectl describe svc ` which gives details on warnings/errors of external IP not getting configured. Refer this [stack post](https://stackoverflow.com/questions/58182760/external-ip-pending-kubernetes-load-balancer) for information and can you provide details on the IP address being used in the API call i.e., http://192.168.49.2:30070 – Goli Nikitha Apr 06 '22 at 13:16
  • When it was still running in a docker container I could use localhost:8080, but now I'm not sure, I tried the other ip `10.106.42.56:8080` and that didn't work either. So not sure where to look for the IP (Edited post with describe svc command). I also added an ingress in the yaml and that one returns almost nothing either. – zhrgci Apr 06 '22 at 13:25
  • externalIP:port will make us map to the cluster from external sources. but 10.106.42.56 seems to be clusterIP, so we access through `10.106.42.56:8080` cluster IP from external sources and I see that external IP is not yet configured for loadbalancer, if that is configured we can access the cluster from external sources. – Goli Nikitha Apr 06 '22 at 14:15
  • But how does one configure the external IP that is pending? Because the post doesn't actually say how to do that (I also don't have any error messages) – zhrgci Apr 06 '22 at 18:50
  • Refer to this [stack post](https://stackoverflow.com/questions/44110876/kubernetes-service-external-ip-pending) for more information on resolving issues with pending external ip and this [document](https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/) for more information on load balancers. – Goli Nikitha Apr 11 '22 at 06:00