Kubernetes----部署单节点Redis

网友投稿 284 2022-09-10

Kubernetes----部署单节点Redis

一、创建ConfigMap

(1)首先创建命名空间

kubectl create namespace ospp

(2)编写redis-config.yaml文件,内容如下:

apiVersion: v1kind: ConfigMapmetadata: name: redis-config namespace: ospp labels: app: redisdata: redis.conf: |- dir /srv port 6379 bind 0.0.0.0 appendonly yes daemonize no #protected-mode no requirepass test pidfile /srv/redis-6379.pid

(3)使用如下命令创建configmap

[root@master ospp]# kubectl apply -f redis-config.yamlconfigmap/redis-config created[root@master ospp]#

二、创建Redis

(1)编写redis.yaml文件,内容如下:

apiVersion: apps/v1kind: Deploymentmetadata: name: redis namespace: ospp labels: app: redisspec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: containers: - name: redis image: redis:5.0.7 command: - "sh" - "-c" - "redis-server /usr/local/redis/redis.conf" ports: - containerPort: 6379 resources: limits: cpu: 1000m memory: 1024Mi requests: cpu: 1000m memory: 1024Mi livenessProbe: tcpSocket: port: 6379 initialDelaySeconds: 300 timeoutSeconds: 1 periodSeconds: 10 successThreshold: 1 failureThreshold: 3 readinessProbe: tcpSocket: port: 6379 initialDelaySeconds: 5 timeoutSeconds: 1 periodSeconds: 10 successThreshold: 1 failureThreshold: 3 volumeMounts: - name: config mountPath: /usr/local/redis/redis.conf subPath: redis.conf volumes: - name: config configMap: name: redis-config---apiVersion: v1kind: Servicemetadata: name: service-redis namespace: osppspec: ports: - port: 6379 protocol: TCP targetPort: 6379 nodePort: 30120 selector: app: redis type:

(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 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 [root@master ospp]#

三、验证redis

(1)若为安装redis-cli,先安装redis-cli

wget -zxvf redis-stable.tar.gzmv redis-stable /usr/local/src/cd /usr/local/srccd redis-stable/ make redis-clicp

(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]#

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:特斯拉Model 3涨价!标准续航升级版车型上调1000元!
下一篇:Kubernetes----配置Secret存储
相关文章

 发表评论

暂时没有评论,来抢沙发吧~