Deploying Redis on Alibaba Cloud Container Server for Kubernetes

Background: Understanding Kubernetes and Redis

Kubernetes and Alibaba Cloud Container Service for Kubernetes (ACK)

Redis and Its Related Architecture

Procedure

Setting up for Redis to Be Deployed on ACK

$ brew install aliyun-cli
aliyun configure
Configuring profile 'default' ...
Aliyun Access Key ID [None]: <Your AccessKey ID>
Aliyun Access Key Secret [None]: <Your AccessKey Secret>
Default Region Id [None]: cn-hangzhou
Default output format [json]: json
Default Languate [zh]: zh
vi create.json
{
"password": "TestPwd124",
"region_id": "cn-hangzhou",
"instance_type": "ecs.n1.small",
"name": "redis-cluster",
"size": 3,
"network_mode": "vpc",
"vpc_id":"vpc-xxxx",
"vswitch_id":"vsw-xxxx",
"subnet_cidr":"172.28.1.0/24",
"data_disk_category": "cloud_ssd",
"data_disk_size": 40,
"need_slb":true,
"ecs_image_id":"centos_7_04_64_20G_alibase_201701015",
"io_optimized":"true",
"release_eip_flag":false
}
aliyun cs POST /clusters --header "Content-Type=application/json" --body "$(cat create.json)"
kubectl create -f redis-master.yaml
kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-master 2/2 Running 0 1m
redis-sentinel-tjldv 1/1 Running 0 34s
apiVersion: v1
kind: Pod
metadata:
labels:
name: redis
redis-sentinel: "true"
role: master
name: redis-master
spec:
containers:
- name: master
image: registry-intl-internal.cn-hangzhou.aliyuncs.com/docker-redis/docker-redis:1.0
env:
- name: MASTER
value: "true"
ports:
- containerPort: 6379
resources:
limits:
cpu: "0.1"
volumeMounts:
- mountPath: /redis-master-data
name: data
- name: sentinel
image: kubernetes/redis:v1
env:
- name: SENTINEL
value: "true"
ports:
- containerPort: 26379
volumes:
- name: data
emptyDir: {}
kubectl create -f sentinel-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
name: sentinel
role: service
name: redis-sentinel
spec:
ports:
- port: 26379
targetPort: 26379
selector:
redis-sentinel: "true"
kubectl create -f redis-controller.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: redis
spec:
replicas: 1
selector:
name: redis
template:
metadata:
labels:
name: redis
spec:
containers:
- name: redis
image: registry-intl-internal.cn-hangzhou.aliyuncs.com/docker-redis/docker-redis:1.0
ports:
- containerPort: 6379
resources:
limits:
cpu: "0.1"
volumeMounts:
- mountPath: /redis-master-data
name: data
volumes:
- name: data
emptyDir: {}
kubectl create -f sentinel-controller.yamlkubectl get rc
NAME DESIRED CURRENT READY AGE
redis 1 1 1 16s
redis-sentinel 1 1 1 5s
apiVersion: v1
kind: ReplicationController
metadata:
name: redis-sentinel
spec:
replicas: 1
selector:
redis-sentinel: "true"
template:
metadata:
labels:
name: redis-sentinel
redis-sentinel: "true"
role: sentinel
spec:
containers:
- name: sentinel
image: registry-intl-internal.cn-hangzhou.aliyuncs.com/docker-redis/docker-redis:1.0
env:
- name: SENTINEL
value: "true"
ports:
- containerPort: 26379
kubectl scale rc redis --replicas=3
kubectl scale rc redis-sentinel --replicas=3
kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-l9w48 1/1 Running 0 25s
redis-master 2/2 Running 0 3m
redis-r43mk 1/1 Running 0 25s
redis-sentinel-8k933 1/1 Running 0 11s
redis-sentinel-jhl6v 1/1 Running 0 11s
redis-sentinel-tjldv 1/1 Running 0 2m
kubectl exec redis-master -i -t -- bash -il
root@redis-master:/data# redis-cli ROLE
1) "master"
2) (integer) 38785
3) 1) 1) "10.4.2.6"
2) "6379"
3) "38640"
2) 1) "10.4.0.5"
2) "6379"
3) "38640"

Testing the deployment

kubectl delete pod redis-master
kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-4bzrb 1/1 Running 0 39s
redis-l9w48 1/1 Running 0 8m
redis-r43mk 1/1 Running 0 8m
redis-sentinel-8k933 1/1 Running 0 8m
redis-sentinel-jhl6v 1/1 Running 0 8m
redis-sentinel-tjldv 1/1 Running 0 10m
kubectl exec redis-l9w48 -i -t -- bash -il
root@redis-l9w48:/data# redis-cli ROLE
1) "master"
2) (integer) 15093
3) 1) 1) "10.4.0.5"
2) "6379"
3) "14962"
2) 1) "10.4.1.9"
2) "6379"
3) "14962"
kubectl exec redis-4bzrb -i -t -- bash -il
root@redis-4bzrb:/data# redis-cli ROLE
1) "slave"
2) "10.4.2.6"
3) (integer) 6379
4) "connected"
5) (integer) 63651
kubectl delete pod redis-r43mk
kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-2xdlv 1/1 Running 0 41s
redis-4bzrb 1/1 Running 0 10m
redis-l9w48 1/1 Running 0 18m
redis-sentinel-8k933 1/1 Running 0 17m
redis-sentinel-jhl6v 1/1 Running 0 17m
redis-sentinel-tjldv 1/1 Running 0 20m
kubectl exec redis-2xdlv -i -t -- bash -il
root@redis-2xdlv:/data# redis-cli ROLE
1) "slave"
2) "10.4.2.6"
3) (integer) 6379
4) "connected"
5) (integer) 114997
kubectl delete pod redis-sentinel-tjldv
kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-2xdlv 1/1 Running 0 4m
redis-4bzrb 1/1 Running 0 14m
redis-l9w48 1/1 Running 0 22m
redis-sentinel-2rpdd 1/1 Running 0 38s
redis-sentinel-8k933 1/1 Running 0 21m
redis-sentinel-jhl6v 1/1 Running 0 21m
kubectl scale rc redis --replicas=5
kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-16lm8 1/1 Running 0 32s
redis-2xdlv 1/1 Running 0 12m
redis-4bzrb 1/1 Running 0 22m
redis-l9w48 1/1 Running 0 29m
redis-sentinel-2rpdd 1/1 Running 0 8m
redis-sentinel-8k933 1/1 Running 0 29m
redis-sentinel-jhl6v 1/1 Running 0 29m
redis-sl9pq 1/1 Running 0 32s
kubectl exec redis-16lm8 -i -t -- bash -il
root@redis-16lm8:/data# redis-cli ROLE
1) "slave"
2) "10.4.2.6"
3) (integer) 6379
4) "connected"
5) (integer) 259108
kubectl exec redis-sl9pq -i -t -- bash -il
root@redis-sl9pq:/data# redis-cli ROLE
1) "slave"
2) "10.4.2.6"
3) (integer) 6379
4) "connected"
5) (integer) 281808
kubectl exec redis-l9w48 -i -t -- bash -il
root@redis-l9w48:/data# redis-cli ROLE
1) "master"
2) (integer) 319409
3) 1) 1) "10.4.1.9"
2) "6379"
3) "319147"
2) 1) "10.4.1.10"
2) "6379"
3) "319409"
3) 1) "10.4.1.11"
2) "6379"
3) "319147"
4) 1) "10.4.0.7"
2) "6379"
3) "319409"
kubectl scale rc redis --replicas=2
kubectl get pods
NAME READY STATUS RESTARTS AGE
redis-4bzrb 1/1 Running 0 32m
redis-l9w48 1/1 Running 0 40m
redis-sentinel-2rpdd 1/1 Running 0 19mr
edis-sentinel-8k933 1/1 Running 0 40m
redis-sentinel-jhl6v 1/1 Running 0 40m
kubectl exec redis-4bzrb -i -t -- bash -il
root@redis-4bzrb:/data# redis-cli ROLE
1) "slave"
2) "10.4.2.6"
3) (integer) 6379
4) "connected"
5) (integer) 384454
kubectl exec redis-l9w48 -i -t -- bash -il
root@redis-l9w48:/data# redis-cli ROLE
1) "master"
2) (integer) 403327
3) 1) 1) "10.4.1.9"
2) "6379"
3) "403327"

References

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

4.97K Followers

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com