Redis as a Sidecar to a Container/POD?

1/26/2020

I have a need to run two services within a container/POD ...

1. An App
2. Redis - the App uses it

Is it possible, say by making the Redis a Sidecar?

-- Naga Vijayapuram
containers
docker
kubernetes
kubernetes-pod
sidecar

2 Answers

1/26/2020

You can make it if you want to tie the lifecycle of redis with single instance of your app. You just need to create a pod with multiple containers. You can access redis on localhost from your app if they are running in same pod.

https://kubernetes.io/docs/tasks/access-application-cluster/communicate-containers-same-pod-shared-volume/#creating-a-pod-that-runs-two-containers

apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:
  containers:
  - name: app
    image: myapp
  - name: redis
    image: redis

Your question sounds more like an XY problem. Why not make redis as a separate pod and access it via a service? That way you can scale your app independently.

-- Shashank V
Source: StackOverflow

1/26/2020

you just need to make a two-container pod, something like this:

    containers:
  - name: 1st
    image: redis
...
  - name: 2nd
    image: app
-- Alex
Source: StackOverflow