(1)首先创建命名空间
kubectl create namespace ospp
(2)编写redis-config.yaml文件,内容如下:
apiVersion: v1kind: ConfigMapmetadata:name: redis-confignamespace: ospplabels:app: redisdata:redis.conf: |-dir /srvport 6379bind 0.0.0.0appendonly yesdaemonize no#protected-mode norequirepass testpidfile /srv/redis-6379.pid
(3)使用如下命令创建configmap
[root@master ospp]# kubectl apply -f redis-config.yamlconfigmap/redis-config created[root@master ospp]#
(1)编写redis.yaml文件,内容如下:
apiVersion: apps/v1kind: Deploymentmetadata:name: redisnamespace: ospplabels:app: redisspec:replicas: 1selector:matchLabels:app: redistemplate:metadata:labels:app: redisspec:containers:- name: redisimage: redis:5.0.7command:- "sh"- "-c"- "redis-server /usr/local/redis/redis.conf"ports:- containerPort: 6379resources:limits:cpu: 1000mmemory: 1024Mirequests:cpu: 1000mmemory: 1024MilivenessProbe:tcpSocket:port: 6379initialDelaySeconds: 300timeoutSeconds: 1periodSeconds: 10successThreshold: 1failureThreshold: 3readinessProbe:tcpSocket:port: 6379initialDelaySeconds: 5timeoutSeconds: 1periodSeconds: 10successThreshold: 1failureThreshold: 3volumeMounts:- name: configmountPath: /usr/local/redis/redis.confsubPath: redis.confvolumes:- name: configconfigMap:name: redis-config---apiVersion: v1kind: Servicemetadata:name: service-redisnamespace: osppspec:ports:- port: 6379protocol: TCPtargetPort: 6379nodePort: 30120selector:app: redistype: NodePort
(2)使用如下命令创建redis
[root@master ospp]# kubectl apply -f redis.yamldeployment.apps/redis createdservice/service-redis unchanged[root@master ospp]#
(3)查看创建资源如下:
[root@master ospp]# kubectl get service,deploy,pod -n ospp -o wideNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTORservice/service-redis NodePort 10.100.68.76 <none> 6379:30120/TCP 2m8s app=redisNAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTORdeployment.apps/redis 1/1 1 1 36s redis redis:5.0.7 app=redisNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESpod/redis-748df49b99-kdhx5 1/1 Running 0 36s 10.244.2.146 node2 <none> <none>[root@master ospp]#
(1)若为安装redis-cli,先安装redis-cli
wget http://download.redis.io/redis-stable.tar.gztar -zxvf redis-stable.tar.gzmv redis-stable /usr/local/src/cd /usr/local/srccd redis-stable/make redis-clicp src/redis-cli /usr/local/bin/
(2)然后链接redis,如下表示OK
[root@master redis-stable]# redis-cli -h 192.168.16.40 -p 30120192.168.16.40:30120> keys *(error) NOAUTH Authentication required.192.168.16.40:30120> auth testOK192.168.16.40:30120> exit[root@master redis-stable]#