Skip to content

Latest commit

 

History

History
145 lines (124 loc) · 3.03 KB

01-60-gcp-redis-instance.md

File metadata and controls

145 lines (124 loc) · 3.03 KB

GCP Redis Instance Tutorial

This tutorial shows how to instantiate Redis and connect to it.

Simple Example

This example showcases how to instantiate Redis, connect a Pod to it, and send a PING command.

  1. Instantiate Redis

Note

This action may take 10+ min

apiVersion: cloud-resources.kyma-project.io/v1beta1
kind: GcpRedisInstance
metadata:
  name: gcpredisinstance-simple-example
spec:
  redisTier: "S1"
  1. Instantiate the redis-cli Pod
apiVersion: v1
kind: Pod
metadata:
  name: gcpredisinstance-simple-example-probe
spec:
  containers:
  - name: redis-cli
    image: redis:latest
    command: ["/bin/sleep"]
    args: ["999999999999"]
    env:
    - name: HOST
      valueFrom:
        secretKeyRef:
          key: host
          name: gcpredisinstance-simple-example
    - name: PORT
      valueFrom:
        secretKeyRef:
          key: port
          name: gcpredisinstance-simple-example
    volumeMounts:
    - name: mounted
      mountPath: /mnt
  volumes:
  - name: mounted
    secret:
      secretName: gcpredisinstance-simple-example
  1. Exec into the Pod:
kubectl exec -i -t gcpredisinstance-simple-example-probe -c redis-cli -- sh -c "clear; (bash || ash || sh)"
  1. Exec a PING command:
redis-cli -h $HOST -p $PORT --tls --cacert /mnt/CaCert.pem PING

You should receive PONG back from the server.

Complex Example

This example showcases how to instantiate Redis by using most of the spec fields, connect a Pod to it, and send a PING command.

  1. Instantiate Redis

Note

This action may take 10+ min

apiVersion: cloud-resources.kyma-project.io/v1beta1
kind: GcpRedisInstance
metadata:
  name: gcpredisinstance-complex-example
spec:
  redisTier: "P1"
  redisVersion: REDIS_7_2
  authEnabled: true
  redisConfigs:
    maxmemory-policy: volatile-lru
    activedefrag: "yes"
  maintenancePolicy:
    dayOfWeek:
      day: "SATURDAY"
      startTime:
          hours: 15
          minutes: 45
  1. Instantiate the redis-cli Pod
apiVersion: v1
kind: Pod
metadata:
  name: gcpredisinstance-complex-example-probe
spec:
  containers:
  - name: redis-cli
    image: redis:latest
    command: ["/bin/sleep"]
    args: ["999999999999"]
    env:
    - name: HOST
      valueFrom:
        secretKeyRef:
          key: host
          name: gcpredisinstance-complex-example
    - name: PORT
      valueFrom:
        secretKeyRef:
          key: port
          name: gcpredisinstance-complex-example
    - name: AUTH_STRING
      valueFrom:
        secretKeyRef:
          key: authString
          name: gcpredisinstance-complex-example
    volumeMounts:
    - name: mounted
      mountPath: /mnt
  volumes:
  - name: mounted
    secret:
      secretName: gcpredisinstance-complex-example
  1. Exec into the Pod:
kubectl exec -i -t gcpredisinstance-complex-example-probe -c redis-cli -- sh -c "clear; (bash || ash || sh)"
  1. Exec a PING command:
redis-cli -h $HOST -p $PORT -a $AUTH_STRING --tls --cacert /mnt/CaCert.pem PING

You should receive PONG back from the server.