I have a requirement where my java app is connecting with redis server
This is my redis config file
apiVersion: v1 kind: ConfigMap metadata: name: redis-config data: SPRING_REDIS_HOST: redis-service # Replace with your Redis service name SPRING_REDIS_PORT: '6379' # Redis default portThis is my secret file apiVersion: v1 kind: Secret # For a secret file, the kind should be "Secret" metadata: name: redis-secret # This is a user-defined name for the Secret type: Opaque # Default type for a secret file data: SPRING_REDIS_PASSWORD: cmVkaXNwYXNzd29yZA== # The value here should be converted to base64this is my redis deployment and service apiVersion: apps/v1kind: Deploymentmetadata: labels: name: redis component: cache name: redisspec: replicas: 1 selector: matchLabels: name: redis template: metadata: labels: name: redis component: cache spec: containers: - name: redis image: redis:latest imagePullPolicy: Always args: ["--requirepass", "$(REDIS_PASS)"] ports: - containerPort: 6379 name: redis env: - name: MASTER value: "true" - name: REDIS_PASS valueFrom: secretKeyRef: name: redis-secret key: SPRING_REDIS_PASSWORD---apiVersion: v1kind: Servicemetadata: name: redis-servicespec: selector: app: redis ports: - protocol: TCP port: 6379 # Default Redis port targetPort: 6379 # Target port on the pods
this is my java application pod where i am passing the env variables
apiVersion: apps/v1kind: Deployment # Deployment file kind should be "Deployment"metadata: name: cartsmicroservice-deployment labels: app: cartsmicroservicespec: replicas: 1 # How many pods you want to create selector: matchLabels: app: cartsmicroservice template: metadata: labels: app: cartsmicroservice spec: containers: - name: cartsmicroservice image: faizannaeem1994/cartsmicroservice:latest # Image name; using official mongo image with tag 7.0 ports: - containerPort: 8001 env: - name: SPRING_REDIS_HOST # Environment variables used in the code valueFrom: configMapKeyRef: name: redis-config # Secret file metadata name key: SPRING_REDIS_HOST # Defined in secret file - name: SPRING_REDIS_PORT # Environment variables used in the code valueFrom: configMapKeyRef: name: redis-config # Secret file metadata name key: SPRING_REDIS_PORT # Defined in secret file - name: SPRING_REDIS_PASSWORD # Environment variables used in the code valueFrom: secretKeyRef: name: redis-secret # Secret file metadata name key: SPRING_REDIS_PASSWORD # Defined in secret file---# Here we describe serviceapiVersion: v1kind: Service # It should be "Service"metadata: name: cartsmicroservice-service # It can be anything (remember in config file we use this service name)spec: type: NodePort # Make it an external service so we can access it selector: app: cartsmicroservice # It should match the name of the pods so service knows for which pods it should forward the request ports: - protocol: TCP port: 8001 # It can be anything (better to make it the same as container port) targetPort: 8001 # It should be the same as the container port nodePort: 30300 # Range is from 30000 to 32767
Unable to connect to redis-service/ unresolved :6379
I have checked the logs of the redis service it is running , but when i deploy the java app it gives me error which i am not getting