Error while using voting-app

I have created a kubeadm cluster with one master and one worker node running. I am trying to deploy the voting-app in this cluster and getting an error when voting-app tries to communicate with the redis pod. Before clicking the voting option from the URL, the pods were up and running.

10.244.1.1 - - [13/Feb/2023:06:13:47 +0000] "GET / HTTP/1.1" 200 1287 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.78"
[2023-02-13 06:13:53,537] ERROR in app: Exception on / [POST]
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python2.7/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/app/app.py", line 31, in hello
    redis.rpush('votes', data)
  File "/usr/local/lib/python2.7/site-packages/redis/client.py", line 2016, in rpush
    return self.execute_command('RPUSH', name, *values)
  File "/usr/local/lib/python2.7/site-packages/redis/client.py", line 898, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/usr/local/lib/python2.7/site-packages/redis/connection.py", line 1192, in get_connection
    connection.connect()
  File "/usr/local/lib/python2.7/site-packages/redis/connection.py", line 563, in connect
    raise ConnectionError(self._error_message(e))
ConnectionError: Error -3 connecting to redis:6379. Try again.

When I click the voting button, it throws Internal Server Error (500) and then the worker app will get CrashLoopBackOff state.

System.AggregateException: One or more errors occurred. (Resource temporarily unavailable) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: Resource temporarily unavailable
   at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
   at System.Net.Dns.ResolveCallback(Object context)
--- End of stack trace from previous location where exception was thrown ---
kubectl get pods,svc -o wide
NAME                 READY   STATUS    RESTARTS   AGE   IP            NODE       NOMINATED NODE   READINESS GATES
pod/postgres-pod     1/1     Running   0          45m   10.244.1.83   worker-1   <none>           <none>
pod/redis-pod        1/1     Running   0          46m   10.244.1.82   worker-1   <none>           <none>
pod/result-app-pod   1/1     Running   0          44m   10.244.1.85   worker-1   <none>           <none>
pod/voting-app-pod   1/1     Running   0          41m   10.244.1.86   worker-1   <none>           <none>
pod/worker-app-pod   1/1     Running   0          9s    10.244.1.88   worker-1   <none>           <none>

NAME                     TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE   SELECTOR
service/db               ClusterIP   10.110.106.32    <none>        5432/TCP       45m   app=demo-voting-app,name=postgres-pod
service/kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP        13d   <none>
service/redis            ClusterIP   10.104.69.203    <none>        6379/TCP       45m   app=demo-voting-app,name=redis-pod
service/result-service   NodePort    10.103.67.16     <none>        80:30005/TCP   44m   app=demo-voting-app,name=result-app-pod
service/voting-service   NodePort    10.101.211.227   <none>        80:30004/TCP   41m   app=demo-voting-app,name=voting-app-pod
kubectl describe pods voting-app-pod  | grep Image
    Image:          kodekloud/examplevotingapp_vote:v1
    Image ID:       docker.io/kodekloud/examplevotingapp_vote@sha256:56c6e895bbf9eb49b8696d84b296c13b43e1855a73500484adc25f17246ce498
kubectl describe pods redis-pod  | grep Image
    Image:          redis
    Image ID:       docker.io/library/redis@sha256:6a59f1cbb8d28ac484176d52c473494859a512ddba3ea62a547258cf16c9b3ae
kubectl describe pods worker-app-pod  | grep Image
    Image:          kodekloud/examplevotingapp_worker:v1
    Image ID:       docker.io/kodekloud/examplevotingapp_worker@sha256:741e3aaaa812af72ce0c7fc5889ba31c3f90c79e650c2cb31807fffc60622263

I have tried deploying the application as pods and as deployment. In both cases, I am getting the same error. I would appreciate any help. (edited)

Hi @sreejith.k,

It seems like the issue you’re facing is coming from service or redis pod himself. Try to debug the service to see if it’s received a request from pod.

Can you please also provide us the yaml file you use?

Regard

Hi @mmkmou,
Thank you for the response.
Yes, I have just reused configuration details from the session “Kubernetes for the absolute beginners.” I didn’t debug specifically on the application side as I am not an expert with python and I don’t have the source code. Please see the config files below as I am not able to upload the text version or zipper version.

redis-deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-deploy
  labels:
    name: redis-deploy
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis-pod
      app: demo-voting-app

  template:
    metadata:
      name: redis-pod
      labels:
        name: redis-pod
        app: demo-voting-app
    spec:
      containers:
        - name: redis
          image: redis
          ports:
            - containerPort: 6379

voting-deployment

apiVersion: apps/v1
kind: Deployment
metadata:
  name: voting-app-deploy
  labels:
    name: voting-app-deploy
    app: demo-voting-app
spec:
  replicas: 1
  selector:
    matchLabels:
      name: voting-app-pod
      app: demo-voting-app

  template:
    metadata:
      name: voting-app-pod
      labels:
        name: voting-app-pod
        app: demo-voting-app
    spec:
      containers:
        - name: voting-app
          image: kodekloud/examplevotingapp_vote:v1
          ports:
            - containerPort: 80

redis-service

apiVersion: v1
kind: Service
metadata:
  name: redis
  labels:
    name: redis-service
    app: demo-voting-app
spec:
  ports:
    - port: 6379
      targetPort: 6379
  selector:
    name: redis-pod
    app: demo-voting-app

voting-service

apiVersion: v1
kind: Service
metadata:
  name: voting-service
  labels:
    name: voting-service
    app: demo-voting-app
spec:
  type: NodePort
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30004
  selector:
    name: voting-app-pod
    app: demo-voting-app

Thanks
Sreejith

I have changed the image in the worker deployment file to dockersamples/examplevotingapp_worker:latest. And that solved the issues for me.
/Sreejith

1 Like

Nice to see you fix it your self