偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

「云原生」Redis on K8s 編排部署講解與實戰(zhàn)操作

云計算 云原生
Redis有三種集群模式:主從模式,Sentinel(哨兵)模式,Cluster模式,這三種模式環(huán)境編排部署都會在本文章介紹與實戰(zhàn)操作。

一、概述

REmote DIctionary Server(Redis) 是一個由 Salvatore Sanfilippo 寫的 key-value 存儲系統(tǒng),是跨平臺的非關系型數(shù)據(jù)庫。

Redis有三種集群模式:主從模式,Sentinel(哨兵)模式,Cluster模式,這三種模式環(huán)境編排部署都會在本文章介紹與實戰(zhàn)操作。

二、redis 主從模式編排部署實戰(zhàn)操作

地址:https://artifacthub.io/packages/helm/bitnami/redis

1)下載chart 包

helm repo add bitnami https://charts.bitnami.com/bitnami

helm pull bitnami/redis --version 17.3.7

tar -xf redis-17.3.7.tgz

2)構建鏡像

這里就不重新構建鏡像了,只是把遠程鏡像tag一下,推到本地harbor倉庫加速下載鏡像。有不清楚怎么構建鏡像的小伙伴,可以私信或者留言。

docker pull docker.io/bitnami/redis:7.0.5-debian-11-r7

# tag
docker tag docker.io/bitnami/redis:7.0.5-debian-11-r7 myharbor.com/bigdata/redis:7.0.5-debian-11-r7

# 推送鏡像到本地harbor倉庫
docker push myharbor.com/bigdata/redis:7.0.5-debian-11-r7

3)修改yaml編排

  • redis/templates/master/pv.yaml

新增pv.yaml文件,內容如下:

{{- range .Values.master.persistence.local }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ .name }}
labels:
name: {{ .name }}
spec:
storageClassName: {{ $.Values.master.persistence.storageClass }}
capacity:
storage: {{ $.Values.master.persistence.size }}
accessModes:
- ReadWriteOnce
local:
path: {{ .path }}
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- {{ .host }}
---
{{- end }}
  • redis/templates/replicas/pv.yaml

新增pv.yaml文件,內容如下:

{{- range .Values.replica.persistence.local }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ .name }}
labels:
name: {{ .name }}
spec:
storageClassName: {{ $.Values.replica.persistence.storageClass }}
capacity:
storage: {{ $.Values.replica.persistence.size }}
accessModes:
- ReadWriteOnce
local:
path: {{ .path }}
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- {{ .host }}
---
{{- end }}
  • redis/values.yaml
global:
redis:
password: "123456"

...

image:
registry: myharbor.com
repository: bigdata/redis
tag: 7.0.5-debian-11-r7

master:
count: 1
persistence:
enabled: true
size: 8Gi
storageClass: "local-redis-storage"
local:
- name: redis-0
host: "local-168-182-110"
path: "/opt/bigdata/servers/redis/data/data1"

replica:
replicaCount: 2
persistence:
enabled: true
size: 8Gi
storageClass: "local-redis-storage"
local:
- name: redis-1
host: "local-168-182-111"
path: "/opt/bigdata/servers/redis/data/data1"
- name: redis-2
host: "local-168-182-112"
path: "/opt/bigdata/servers/redis/data/data1"

4)開始部署

# 創(chuàng)建存儲目錄
mkdir /opt/bigdata/servers/redis/data/data1

# 先檢查語法
helm lint ./redis

# 開始安裝
helm install redis ./redis -n redis --create-namespace

NOTES

REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 17.3.7
APP VERSION: 7.0.5

** Please be patient while the chart is being deployed **

Redis? can be accessed on the following DNS names from within your cluster:

redis-master.redis.svc.cluster.local for read/write operations (port 6379)
redis-replicas.redis.svc.cluster.local for read-only operations (port 6379)



To get your password run:

export REDIS_PASSWORD=$(kubectl get secret --namespace redis redis -o jsonpath="{.data.redis-password}" | base64 -d)

To connect to your Redis? server:

1. Run a Redis? pod that you can use as a client:

kubectl run --namespace redis redis-client --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image myharbor.com/bigdata/redis:7.0.5-debian-11-r7 --command -- sleep infinity

Use the following command to attach to the pod:

kubectl exec --tty -i redis-client \
--namespace redis -- bash

2. Connect using the Redis? CLI:
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-master
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-replicas

To connect to your database from outside the cluster execute the following commands:

kubectl port-forward --namespace redis svc/redis-master 6379:6379 &
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379

5)測試驗證

kubectl get pods,svc -n redis -owide

# 登錄master,可讀可寫
kubectl exec -it redis-master-0 -n redis -- redis-cli -h redis-master -a $(kubectl get secret --namespace redis redis -o jsonpath="{.data.redis-password}" | base64 -d)

# 登錄slave,只讀
kubectl exec -it redis-master-0 -n redis -- redis-cli -h redis-replicas -a $(kubectl get secret --namespace redis redis -o jsonpath="{.data.redis-password}" | base64 -d)

6)卸載

helm uninstall redis-sentinel -n redis-sentinel
# delete ns
kubectl delete ns redis-sentinel --force
# delete pv
kubectl delete pv `kubectl get pv|grep ^redis-|awk '{print $1}'` --force

rm -fr /opt/bigdata/servers/redis/data/data1/*

三、redis 哨兵模式編排部署實戰(zhàn)操作

主從模式的弊端就是不具備高可用性,當master掛掉以后,Redis將不能再對外提供寫入操作,因此sentinel應運而生。

1)構建鏡像

這里也重新構建鏡像了,有不懂構建鏡像的小伙伴可以在評論下方留言。這里也只是把遠程的鏡像推送到本地harbor。

docker pull docker.io/bitnami/redis-sentinel:7.0.5-debian-11-r6
# tag
docker tag docker.io/bitnami/redis-sentinel:7.0.5-debian-11-r6 myharbor.com/bigdata/redis-sentinel:7.0.5-debian-11-r6
# push
docker push myharbor.com/bigdata/redis-sentinel:7.0.5-debian-11-r6

2)修改yaml編排

  • redis-sentinel/values.yaml
replica:
# replica.replicaCount與sentinel.quorum值一樣
replicaCount: 3
storageClass: "local-redis-storage"
local:
- name: redis-0
host: "local-168-182-110"
path: "/opt/bigdata/servers/redis/data/data1"
- name: redis-1
host: "local-168-182-111"
path: "/opt/bigdata/servers/redis/data/data1"
- name: redis-2
host: "local-168-182-112"
path: "/opt/bigdata/servers/redis/data/data1"

sentinel:
enabled: true
image:
registry: myharbor.com
repository: bigdata/redis-sentinel
tag: 7.0.5-debian-11-r6
quorum: 3
  • redis-sentinel/templates/replicas/pv.yaml

新增pv.yaml文件,內容如下:

{{- range .Values.sentinel.persistence.local }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ .name }}
labels:
name: {{ .name }}
spec:
storageClassName: {{ $.Values.sentinel.persistence.storageClass }}
capacity:
storage: {{ $.Values.sentinel.persistence.size }}
accessModes:
- ReadWriteOnce
local:
path: {{ .path }}
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- {{ .host }}
---
{{- end }}

3)開始部署

# 創(chuàng)建存儲目錄
mkdir -p /opt/bigdata/servers/redis/data/data1

helm install redis-sentinel ./redis-sentinel -n redis-sentinel --create-namespace

NOTES

NAME: redis-sentinel
LAST DEPLOYED: Fri Nov 4 22:42:52 2022
NAMESPACE: redis-sentinel
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
CHART NAME: redis
CHART VERSION: 17.3.7
APP VERSION: 7.0.5

** Please be patient while the chart is being deployed **

Redis? can be accessed via port 6379 on the following DNS name from within your cluster:

redis-sentinel.redis-sentinel.svc.cluster.local for read only operations

For read/write operations, first access the Redis? Sentinel cluster, which is available in port 26379 using the same domain name above.



To get your password run:

export REDIS_PASSWORD=$(kubectl get secret --namespace redis-sentinel redis-sentinel -o jsonpath="{.data.redis-password}" | base64 -d)

To connect to your Redis? server:

1. Run a Redis? pod that you can use as a client:

kubectl run --namespace redis-sentinel redis-client --restart='Never' --env REDIS_PASSWORD=$REDIS_PASSWORD --image myharbor.com/bigdata/redis:7.0.5-debian-11-r7 --command -- sleep infinity

Use the following command to attach to the pod:

kubectl exec --tty -i redis-client \
--namespace redis-sentinel -- bash

2. Connect using the Redis? CLI:
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-sentinel -p 6379 # Read only operations
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h redis-sentinel -p 26379 # Sentinel access

To connect to your database from outside the cluster execute the following commands:

kubectl port-forward --namespace redis-sentinel svc/redis-sentinel 6379:6379 &
REDISCLI_AUTH="$REDIS_PASSWORD" redis-cli -h 127.0.0.1 -p 6379

查看

kubectl get pods,svc -n redis-sentinel -owide

4)模擬故障測試

# 查看
kubectl exec -it redis-sentinel-node-0 -n redis-sentinel -- redis-cli -h redis-sentinel -a $(kubectl get secret --namespace redis-sentinel redis-sentinel -o jsonpath="{.data.redis-password}" | base64 -d) info replication

模擬故障,kill master pod

kubectl delete pod redis-sentinel-node-0 -n redis-sentinel

再次查看master所在節(jié)點,master節(jié)點已經切換到其它節(jié)點了。

再測試讀寫

# 登錄master節(jié)點
kubectl exec -it redis-sentinel-node-0 -n redis-sentinel -- redis-cli -h redis-sentinel-node-2.redis-sentinel-headless -a $(kubectl get secret --namespace redis-sentinel redis-sentinel -o jsonpath="{.data.redis-password}" | base64 -d)

# 登錄slave節(jié)點
kubectl exec -it redis-sentinel-node-0 -n redis-sentinel -- redis-cli -h redis-sentinel-node-0.redis-sentinel-headless -a $(kubectl get secret --namespace redis-sentinel redis-sentinel -o jsonpath="{.data.redis-password}" | base64 -d)

5)卸載

helm uninstall redis-sentinel -n redis
# delete ns
kubectl delete ns redis --force
# delete pv
kubectl delete pv `kubectl get pv|grep ^redis-|awk '{print $1}'` --force

rm -fr /opt/bigdata/servers/redis/data/data1/*

四、redis 集群模式編排部署實戰(zhàn)操作

集群模式可以說是sentinel+主從模式的結合體,通過cluster可以實現(xiàn)主從和master重選功能,所以如果配置兩個副本三個分片的話,就需要六個Redis實例。因為Redis的數(shù)據(jù)是根據(jù)一定規(guī)則分配到cluster的不同機器的,當數(shù)據(jù)量過大時,可以新增機器進行擴容。

1)下載chart 包

helm repo add bitnami https://charts.bitnami.com/bitnami

helm pull bitnami/redis-cluster --version 8.2.7

tar -xf redis-cluster-8.2.7.tgz

2)構建鏡像

這里就不重新構建鏡像了,只是把遠程鏡像tag一下,推到本地harbor倉庫加速下載鏡像。有不清楚怎么構建鏡像的小伙伴,可以私信或者留言。

docker pull docker.io/bitnami/redis-cluster:7.0.5-debian-11-r9

# tag
docker tag docker.io/bitnami/redis-cluster:7.0.5-debian-11-r9 myharbor.com/bigdata/redis-cluster:7.0.5-debian-11-r9

# 推送鏡像到本地harbor倉庫
docker push myharbor.com/bigdata/redis-cluster:7.0.5-debian-11-r9

3)修改yaml編排

  • redis-cluster/templates/pv.yaml

新增pv.yaml文件,內容如下:

{{- range .Values.persistence.local }}
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: {{ .name }}
labels:
name: {{ .name }}
spec:
storageClassName: {{ $.Values.persistence.storageClass }}
capacity:
storage: {{ $.Values.persistence.size }}
accessModes:
- ReadWriteOnce
local:
path: {{ .path }}
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- {{ .host }}
---
{{- end }}
password: "123456"

...

image:
registry: myharbor.com
repository: bigdata/redis-cluster
tag: 7.0.5-debian-11-r9

...

persistence:
storageClass: "local-redis-cluster-storage"
local:
- name: redis-cluster-0
host: "local-168-182-110"
path: "/opt/bigdata/servers/redis-cluster/data/data1"
- name: redis-cluster-1
host: "local-168-182-110"
path: "/opt/bigdata/servers/redis-cluster/data/data2"
- name: redis-cluster-2
host: "local-168-182-110"
path: "/opt/bigdata/servers/redis-cluster/data/data3"
- name: redis-cluster-3
host: "local-168-182-111"
path: "/opt/bigdata/servers/redis-cluster/data/data1"
- name: redis-cluster-4
host: "local-168-182-111"
path: "/opt/bigdata/servers/redis-cluster/data/data2"
- name: redis-cluster-5
host: "local-168-182-111"
path: "/opt/bigdata/servers/redis-cluster/data/data3"
- name: redis-cluster-6
host: "local-168-182-112"
path: "/opt/bigdata/servers/redis-cluster/data/data1"
- name: redis-cluster-7
host: "local-168-182-112"
path: "/opt/bigdata/servers/redis-cluster/data/data2"
- name: redis-cluster-8
host: "local-168-182-112"
path: "/opt/bigdata/servers/redis-cluster/data/data3"

cluster:
init: true
# 一主兩從(三組)
nodes: 9
replicas: 2

4)開始部署

# 創(chuàng)建存儲目錄
mkdir -p /opt/bigdata/servers/redis-cluster/data/data{1..3}

helm install redis-cluster ./redis-cluster -n redis-cluster --create-namespace

NOTES

NOTES:
CHART NAME: redis-cluster
CHART VERSION: 8.2.7
APP VERSION: 7.0.5** Please be patient while the chart is being deployed **


To get your password run:
export REDIS_PASSWORD=$(kubectl get secret --namespace "redis-cluster" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d)

You have deployed a Redis? Cluster accessible only from within you Kubernetes Cluster.INFO: The Job to create the cluster will be created.To connect to your Redis? cluster:

1. Run a Redis? pod that you can use as a client:
kubectl run --namespace redis-cluster redis-cluster-client --rm --tty -i --restart='Never' \
--env REDIS_PASSWORD=$REDIS_PASSWORD \
--image myharbor.com/bigdata/redis-cluster:7.0.5-debian-11-r9 -- bash

2. Connect using the Redis? CLI:

redis-cli -c -h redis-cluster -a $REDIS_PASSWORD

查看

kubectl get pods,svc -n redis-cluster -owide

5)故障模擬測試

kubectl exec -it redis-cluster-0 -n redis-cluster -- redis-cli -c -h redis-cluster -a $(kubectl get secret --namespace "redis-cluster" redis-cluster -o jsnotallow="{.data.redis-password}" | base64 -d) CLUSTER INFO

kubectl exec -it redis-cluster-0 -n redis-cluster -- redis-cli -c -h redis-cluster -a $(kubectl get secret --namespace "redis-cluster" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d) CLUSTER NODES

刪除其中一個master節(jié)點

kubectl delete pod redis-cluster-1 -n redis-cluster

# 再查看節(jié)點情況
kubectl exec -it redis-cluster-0 -n redis-cluster -- redis-cli -c -h redis-cluster -a $(kubectl get secret --namespace "redis-cluster" redis-cluster -o jsonpath="{.data.redis-password}" | base64 -d) CLUSTER NODES

6)卸載

helm uninstall redis-cluster -n redis-cluster
# delete ns
kubectl delete ns redis-cluster --force
# delete pv
kubectl delete pv `kubectl get pv|grep ^redis-cluster-|awk '{print $1}'` --force

rm -fr /opt/bigdata/servers/redis-cluster/data/data{1..3}/*

git地址:https://gitee.com/hadoop-bigdata/redis-on-k8s?

責任編輯:武曉燕 來源: 今日頭條
相關推薦

2023-03-01 07:42:12

HBase編排部署數(shù)據(jù)

2023-03-06 07:19:50

2023-03-03 07:54:21

2022-11-08 08:55:31

2023-03-07 07:56:37

Sqoopk8s底層

2022-10-14 07:42:50

LuceneHTTPWeb

2022-10-10 12:54:00

Flink運維

2023-02-27 07:40:00

2023-09-11 00:09:18

2022-12-13 09:01:50

云原生組件數(shù)據(jù)

2023-08-29 10:27:32

2023-07-10 07:22:16

2022-11-28 17:22:32

高可用master節(jié)點

2022-12-26 08:14:57

K8sCronhpa定時彈性

2021-04-25 10:26:58

云計算云原生

2023-09-06 08:12:04

k8s云原生

2021-08-13 07:00:41

云原生k8sspringboot

2021-08-26 07:20:05

云原生K8sSpringboot

2024-09-26 09:50:07

2023-11-06 01:17:25

主機容器選項
點贊
收藏

51CTO技術棧公眾號