Can't see my app on browser deploying with Kubernetes

3/26/2020

hope you all well!

I need to see my app on the browser but I believe that I'm missing something here and hope you can help me with this.

[root@kubernetes Docker]# kubectl get all
NAME                           READY   STATUS    RESTARTS   AGE
pod/my-app2-56d5c786dd-n7mqq   1/1     Running   0          19m
pod/nginx-86c57db685-bxkpl     1/1     Running   0          13h

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
service/kubernetes   ClusterIP   10.96.0.1        <none>        443/TCP        31h
service/my-app2      ClusterIP   10.101.108.199   <none>        8085/TCP       12m
service/nginx        NodePort    10.106.14.144    <none>        80:30525/TCP   13h

NAME                      READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/my-app2   1/1     1            1           19m
deployment.apps/nginx     1/1     1            1           13h

NAME                                 DESIRED   CURRENT   READY   AGE
replicaset.apps/my-app2-56d5c786dd   1         1         1       19m
replicaset.apps/nginx-86c57db685     1         1         1       13h

Overall you can see that everything is working fine right, looks the same to me.

To open this on my browser I'm using my IP address from Slave node where the container is allocated. On my app I'm mapping the Hello like this @RequestMapping("/Hello") On my dockerfile to build my image i used this:

[root@kubernetes project]# cat Dockerfile
FROM openjdk:8
COPY microservico-0.0.1-SNAPSHOT.jar microservico-0.0.1-SNAPSHOT.jar
#WORKDIR /usr/src/microservico-0.0.1-SNAPSHOT.jar
EXPOSE 8085
ENTRYPOINT ["java", "-jar", "microservico-0.0.1-SNAPSHOT.jar"]

So at the end, I think I need to call for my app this way.

---> ip:8085/Hello

[root@kubernetes project]# telnet kubeslave 8085
Trying 192.168.***.***...
telnet: connect to address 192.168.***.***: Connection refused

but I still see nothing...

Here is my deploy and service:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app2
  labels:
    app: app
spec:
  selector:
    matchLabels:
      app: app
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        app: app
        role: master
        tier: backend
    spec:
      containers:
      - name: appcontainer
        image: *****this is ok*****:my-java-app
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 8085


apiVersion: v1
kind: Service
metadata:
  name: my-app2
  labels:
    app: app
    role: master
    tier: backend
spec:
  ports:
  - port: 8085
    targetPort: 8085
  selector:
    app: app
    role: master
    tier: backend
-- Bedjase
docker
kubernetes

1 Answer

3/26/2020

You have create a service which is of type ClusterIP(default). This type of service is only for accessing from inside the kubernetes cluster.For accessing it from browser you need to expose the pod via LoadBalancer or Nodeport service. LoadBalancer only works if you are one of supported public cloud otherwise Nodeport need to be used.

https://kubernetes.io/docs/tutorials/stateless-application/expose-external-ip-address/

https://kubernetes.io/docs/tasks/access-application-cluster/service-access-application-cluster/

Other than using service you can use kubectl proxy to access it as well.

If you are on Minikube then follow this

https://kubernetes.io/docs/tutorials/hello-minikube/

-- Arghya Sadhu
Source: StackOverflow