Basically, i have a Deployment that creates 3 containers which scale automatically: PHP-FPM, NGINX and the container that contains the application, all set up with secrets, services and ingress. The application also share the project between PHP-FPM and NGINX, so it's all set up.
Since i want to explore more with K8s, i decided to create a pod with Redis that also mounts a persistent disk (but that's not important). I have also created a service for redis and all works perfectly fine if i SSH into the Redis container and run redis-cli
.
The fun part is that the project can't connect to the pod on which Redis is on. I understand that the containers between pods share the same "local" network and they can be accessed using localhost
.
How do i connect my project to the redis server that is running in other pod, that scales independently? What's wrong with the Redis service?
My Redis service is this:
apiVersion: v1
kind: Service
metadata:
name: redis-service
spec:
ports:
- port: 6379
targetPort: 6379
selector:
app: redis
My Redis pod is powered by a deployment configuration file (i don't necessarily scale it, but i'll look forward into it):
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
labels:
app: redis
spec:
selector:
matchLabels:
app: redis
strategy:
type: Recreate
template:
metadata:
labels:
app: redis
spec:
volumes:
- name: redis-persistent-volume
persistentVolumeClaim:
claimName: redis-pvc
containers:
- image: redis:4.0.11
command: ['redis-server']
name: redis
imagePullPolicy: Always
resources:
limits:
cpu: 250m
memory: 512Mi
requests:
cpu: 250m
memory: 512Mi
ports:
- containerPort: 6379
name: redis
volumeMounts:
- name: redis-persistent-volume
mountPath: /data
Also, when i tap into the kubectl get service
, the Redis server has a Cluster IP:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 21h
nginx-service NodePort 10.100.111.16 <none> 80:30312/TCP 21h
redis-service ClusterIP 10.99.80.141 <none> 6379/TCP 6s