Rancher部署Redis单节点
上一篇介绍了如何Rancher部署Nacos,这里继续介绍通过Rancher部署Redis单节点
2 部署redis
2.1 准备ConfigMap
通过ConfigMap管理redis.conf文件
[root@uat-master standalone]# cat redis.conf
appendonly yes
cluster-enabled no
#cluster-config-file /var/lib/redis/nodes.conf
#cluster-node-timeout 5000
dir /var/lib/redis
port 6379
[root@uat-master standalone]#
[root@uat-master standalone]# kubectl create configmap redis-alone-conf -n middleware --from-file=redis.conf
[root@uat-master standalone]# kubectl get cm -n middleware |grep redis-alone-
redis-alone-conf 1 76m
[root@uat-master standalone]#
Rancher上查看
2.1 准备pvc
yaml文件
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
labels:
cattle.io/creator: norman
name: redis-alone-data
namespace: middleware
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 512Mi
storageClassName: managed-nfs-storage
volumeMode: Filesystem
创建、查看PVC
[root@uat-master standalone]# kubectl create -f pvc.yaml
[root@uat-master standalone]# kubectl get pvc -n middleware |grep redis-alone-data
redis-alone-data Bound pvc-99f64e8c-f196-4f68-9094-29eaba68cf33 512Mi RWO managed-nfs-storage 63m
[root@uat-master standalone]#
2.2 部署redis
yaml文件
[root@uat-master standalone]# cat redis-alone-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: middleware
spec:
#serviceName: redis
replicas: 1
selector:
matchLabels:
app: redis
appCluster: redis-alone
template:
metadata:
labels:
app: redis
appCluster: redis-alone
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: redis:6.0.10
imagePullPolicy: IfNotPresent
command:
- "redis-server"
args:
- "/etc/redis/redis.conf"
- "--protected-mode"
- "no"
resources:
requests:
cpu: "200m"
memory: "250Mi"
ports:
- containerPort: 6379
name: redis
protocol: TCP
volumeMounts:
- name: conf
mountPath: /etc/redis
- name: data
mountPath: /var/lib/redis
subPath: data
volumes:
- name: conf
configMap:
name: redis-alone-conf
items:
- key: redis.conf
path: redis.conf
- name: data
persistentVolumeClaim:
claimName: redis-alone-data
[root@uat-master standalone]#
创建redis Deployment
[root@uat-master standalone]# kubectl create -f redis-alone-deployment.yaml
······
[root@uat-master standalone]# kubectl get pods -n middleware |grep redis
redis-5b6ddfcd68-x22tq 1/1 Running 0 70m
[root@uat-master standalone]#
2.3 部署service
为便于远程访问,这里以NodePort方式部署service
[root@uat-master standalone]# cat redis-alone-service.yaml
apiVersion: v1
kind: Service
metadata:
name: redis-alone-access
namespace: middleware
labels:
app: redis
spec:
selector:
app: redis
appCluster: redis-alone
ports:
- name: redis-access
protocol: TCP
port: 6379
targetPort: 6379
type: NodePort
[root@uat-master standalone]#
创建、查看service
[root@uat-master standalone]# kubectl apply -f redis-alone-service.yaml
service/redis-alone-access unchanged
[root@uat-master standalone]# kubectl get svc -n middleware |grep redis-alone-access
redis-alone-access NodePort 10.43.113.220 <none> 6379:31600/TCP 69m
[root@uat-master standalone]#
3 远程访问redis
先要确保k8s集群主机31600端口能够远程访问
这里使用Another Redis DeskTop Manager 工具,github地址:https://github.com/qishibo/AnotherRedisDesktopManager
配置连接:
连接成功
测试成功