Redis
最后更新于
apiVersion: v1
kind: PersistentVolume
metadata:
name: data0
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/data0
storageClassName: local-storage
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: data1
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/data1
storageClassName: local-storage
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: data2
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/data2
storageClassName: local-storage
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: data3
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/data3
storageClassName: local-storage
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: data4
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/data4
storageClassName: local-storage
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: data5
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: /data/data5
storageClassName: local-storageapiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-redis-0
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 1Gi
volumeName: data0
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-redis-1
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 1Gi
volumeName: data1
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-redis-2
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 1Gi
volumeName: data2
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-redis-3
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 1Gi
volumeName: data3
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-redis-4
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 1Gi
volumeName: data4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: data-redis-5
spec:
accessModes:
- ReadWriteOnce
storageClassName: local-storage
resources:
requests:
storage: 1Gi
volumeName: data5
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START gke_manifests_redis_cluster_statefulset_redis]
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
spec:
serviceName: "redis-cluster"
replicas: 6
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
appCluster: redis-cluster
spec:
terminationGracePeriodSeconds: 20
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- redis
topologyKey: kubernetes.io/hostname
containers:
- name: redis
image: "172.25.0.50/k8s/redis:6.2"
command:
- "redis-server"
args:
- "/conf/redis.conf"
- "--protected-mode"
- "no"
resources:
requests:
cpu: "100m"
memory: "100Mi"
ports:
- name: redis
containerPort: 6379
protocol: "TCP"
- name: cluster
containerPort: 16379
protocol: "TCP"
# [START gke_manifests_redis_cluster_statefulset_redis_probes]
startupProbe:
periodSeconds: 5
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 20
tcpSocket:
port: redis
livenessProbe:
periodSeconds: 5
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 5
exec:
command: ["sh", "-c", "/probes/liveness.sh"]
readinessProbe:
periodSeconds: 5
timeoutSeconds: 1
successThreshold: 1
failureThreshold: 5
exec:
command: ["sh", "-c", "/probes/readiness.sh"]
# [END gke_manifests_redis_cluster_statefulset_redis_probes]
volumeMounts:
- name: conf
mountPath: /conf
readOnly: false
- name: data
mountPath: /data
readOnly: false
- name: probes
mountPath: /probes
readOnly: true
volumes:
- name: conf
configMap:
name: redis-cluster
defaultMode: 0755
- name: probes
configMap:
name: redis-probes
defaultMode: 0555
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi
# [END gke_manifests_redis_cluster_statefulset_redis]
---
# [START gke_manifests_redis_configmap_configmap_redis_cluster]
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-cluster
data:
redis.conf: |+
cluster-enabled yes
cluster-node-timeout 15000
cluster-config-file /data/nodes.conf
appendonly yes
protected-mode no
dir /data
port 6379
---
apiVersion: v1
kind: ConfigMap
metadata:
name: redis-probes
data:
# [START gke_manifests_redis_configmap_configmap_redis_cluster_probes]
readiness.sh: |-
#!/bin/sh
pingResponse="$(redis-cli -h localhost ping)"
if [ "$?" -eq "124" ]; then
echo "PING timed out"
exit 1
fi
if [ "$pingResponse" != "PONG"]; then
echo "$pingResponse"
exit 1
fi
liveness.sh: |-
#!/bin/sh
pingResponse="$(redis-cli -h localhost ping | head -n1 | awk '{print $1;}')"
if [ "$?" -eq "124" ]; then
echo "PING timed out"
exit 1
fi
if [ "$pingResponse" != "PONG"] && [ "$pingResponse" != "LOADING" ] && [ "$pingResponse" != "MASTERDOWN" ]; then
echo "$pingResponse"
exit 1
fi
# [END gke_manifests_redis_configmap_configmap_redis_cluster_probes]
# [END gke_manifests_redis_configmap_configmap_redis_cluster]
---
apiVersion: v1
kind: Service
metadata:
name: redis-cluster
spec:
clusterIP: 172.24.11.151
ports:
- name: redis-port
port: 6379
protocol: TCP
targetPort: 6379
selector:
app: redis
appCluster: redis-cluster
sessionAffinity: None
type: ClusterIP
# [END gke_manifests_redis_service_service_redis_cluster]
---
# [START gke_quickstarts_hello_app_redis_manifests_pbd_minavailable]
# apiVersion: policy/v1
# kind: PodDisruptionBudget
# metadata:
# name: redis-pdb
# spec:
# minAvailable: 3
# selector:
# matchLabels:
# app: redis
# [END gke_quickstarts_hello_app_redis_manifests_pbd_minavailable]# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START gke_quickstarts_hello_app_redis_manifests_roles]
#!/bin/bash
# Usage: ./roles.sh
urls=$(kubectl get pods -l app=redis -o jsonpath='{range.items[*]}{.status.podIP} ')
command="kubectl exec -it redis-0 -- redis-cli --cluster create --cluster-replicas 1 "
for url in $urls
do
command+=$url":6379 "
done
echo "Executing command: " $command
$command
# [END gke_quickstarts_hello_app_redis_manifests_roles]./redis-cli -h 172.8.5.202
192.24.54.1:6379> get name
(error) MOVED 5798 172.8.5.202:6379./redis-cli -h 172.8.5.202 -c