0

I have got 2 deployments in my cluster UI and USER. Both of these are exposed by Cluster IP service. There is an ingress which makes both the services publicly accessible.

Now when I do "kubectl exec -it UI-POD -- /bin/sh" and then try to "ping USER-SERVICE-CLUSTER-IP:PORT" it doesn't work.

All I get is No packet returned i.e. a failure message.

Attaching my .yml file

apiVersion: apps/v1
kind: Deployment
metadata:
  name: user-service-app
  labels:
    app: user-service-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: user-service-app
  template:
    metadata:
      labels:
        app: user-service-app
    spec:
      containers:
      - name: user-service-app
        image: <MY-IMAGE-URL>
        imagePullPolicy: Always
        ports:
        - containerPort: 3000
        livenessProbe:
          httpGet:
            path: /ping
            port: 3000
        readinessProbe:
          httpGet:
            path: /ping
            port: 3000
          
          

---
apiVersion: "v1"
kind: "Service"
metadata:
  name: "user-service-svc"
  namespace: "default"
  labels:
    app: "user-service-app"
spec:
  type: "ClusterIP"
  selector:
    app: "user-service-app"
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 3000

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: ui-service-app
  labels:
    app: ui-service-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ui-service-app
  template:
    metadata:
      labels:
        app: ui-service-app
    spec:
      containers:
      - name: ui-service-app
        image: <MY-IMAGE-URL>
        imagePullPolicy: Always
        ports:
        - containerPort: 3000

---
apiVersion: "v1"
kind: "Service"
metadata:
  name: "ui-service-svc"
  namespace: "default"
  labels:
    app: "ui-service-app"
spec:
  type: "ClusterIP"
  selector:
    app: "ui-service-app"
  ports:
  - protocol: "TCP"
    port: 80
    targetPort: 3000
  


---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: awesome-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  ingressClassName: nginx
  defaultBackend:
    service:
      name: ui-service-svc
      port:
        number: 80
  rules:
  - http:
      paths:      
      - path: /login
        pathType: Prefix
        backend:
          service:
            name: ui-service-svc
            port:
              number: 80
      - path: /user(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: user-service-svc
            port:
              number: 80

1 Answers1

1

Ping operates by means of Internet Control Message Protocol (ICMP) packets. This is not what your service is serving. You can try curl USER-SERVICE-CLUSTER-IP/ping or curl http://user-service-svc/ping within your UI pod.

gohm'c
  • 13,492
  • 1
  • 9
  • 16
  • But the ping works when I change the type of User service to Load balancer instead of ClusterIP. Also I tried accessing the user service from within my UI service application and its not working. Though, I tried the command you suggested and it just gave me curl not present, tried to install it through apt update but apt is also not present. I am using Container-Optimized OS with containerd (cos_containerd) in GKE. @gohm'c – Yashvardhan Nathawat Jun 04 '22 at 06:43
  • `ping` works if the target is a **pod**, not a service. Your question read like you are ping'ing a service. You don't have to install `curl`. Try `kubectl run busybox --image busybox -it -- ash`. Then `wget http://user-service-svc/ping`. If you are not getting a response, check if the pod has status `CrashLoopBackOff`. – gohm'c Jun 04 '22 at 07:45
  • Sorry, if the question was not clear from my side. I am trying to check if I can communicate to my application inside user-service-app from the ui-service-app. Now to check that connection I am doing exec -it inside the ui pod and trying to reach user-service-app through user-service-svc:80. In development side the UI app is making a http api call to user service app, which should use the cluster ip of user-service-svc ideally but, its not working if I use clusterIP but instead by using ingress-ip/user in that api call. – Yashvardhan Nathawat Jun 04 '22 at 09:04
  • And by running your solution i.e. runing a busybox image pod in my cluster and then doing curl its giving me a healthy output which I think means the connection is fine. – Yashvardhan Nathawat Jun 04 '22 at 09:05
  • any Solution for this? @gohm'c – Yashvardhan Nathawat Jun 09 '22 at 04:04
  • You have successfully curl the service `user-service-svc` from another (busybox) pod. Are you now talking about inside your own application? It's better to start a new question. – gohm'c Jun 09 '22 at 07:25
  • The Link for new question https://stackoverflow.com/questions/72556850/accessing-application-inside-a-kubernetes-pod-from-an-another-application-in-a-d @gohm'c – Yashvardhan Nathawat Jun 09 '22 at 08:27