<p>Is there a way to set maxmemory and maxmemory-policy for Redis on Kubernetes?</p>

<p>I am using the command kubectl apply -f redis-cache.yaml</p>

<p>The file redis-cache.yaml contains this content:</p>

<pre><code>apiVersion: apps/v1
data:
  redis-config: |
    maxmemory 256
    maxmemory-policy allkeys-lru
kind: Deployment
metadata:
  name: redis-cache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-cache
  template:
    metadata:
      labels:
        app: redis-cache
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: redis-cache
        image: redis
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 150m
            memory: 256Mi
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: redis-cache
spec:
  ports:
  - port: 6379
  selector:
    app: redis-cache
</code></pre>

cfbd
<p>The Kubernetes <code>deployment</code> doesn't have field named <code>data</code>.</p>

<p>You can provide the configuration via <code>ConfigMap</code> or <code>Secret</code>. The Redis configuration file is located at <code>installdir/redis/etc/redis.conf</code>.</p>

<p><strong>ConfigMap:</strong></p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-config
data:
  redis.conf: |-
    maxmemory 256
    maxmemory-policy allkeys-lru
</code></pre>

<p><strong>Deployment:</strong></p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-cache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-cache
  template:
    metadata:
      labels:
        app: redis-cache
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      volumes:
      - name: redis-config
        configMap:
          name: redis-config
      containers:
      - name: redis-cache
        image: redis
        volumeMounts:
        - name: redis-config
          mountPath: /redis/etc
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 150m
            memory: 256Mi
        ports:
        - containerPort: 6379
          name: redis
</code></pre>
