k8s启动单机redis

前言:
kubernetes启动单机redis,可以测试环境使用。

我的其它相关文档:
《docker-compose快速启动redis》
《helm启动radis-ha》

1. 不使用密码

1. 1 yml文件

创建yml文件如下,可以叫redis.yml

---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: redis
  namespace: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: redis
    spec:
      containers:
      - name: redis
       # 镜像随意什么版本,不愿意选就这样用latest吧
        image: redis:5
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 6379
          protocol: TCP
        volumeMounts:
        - mountPath: /data
          name: redis-data
      volumes:
      - name: redis-data
        persistentVolumeClaim:
          claimName: pv-redis
      imagePullSecrets:
      - name: my-harbor
---
kind: Service
apiVersion: v1
metadata:
  name: redis
  namespace: redis
  labels:
    name: redis
spec:
 type: NodePort
 ports:
 - port: 6379
   targetPort: 6379
   nodePort: 31001
   name: redis-port
 selector:
   name: redis

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
 name: pv-redis
 namespace: redis
spec:
 accessModes:
   - ReadWriteMany
 resources:
   requests:
     storage: 5Gi

1.2 启动

kubectl create -f redis.yml

2. 使用密码

根据上边示例添加如下内容:

  • Deployment中添加了一段挂载configmap
  • 后边加了一段创建Deployment
kind: Deployment
apiVersion: apps/v1
metadata:
  name: redis
  namespace: redis-pub
spec:
  replicas: 1
  selector:
    matchLabels:
      name: redis
  template:
    metadata:
      labels:
        name: redis
    spec:
      containers:
      - name: redis
        image: redis:5
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 6379
          protocol: TCP
        volumeMounts:
        - mountPath: /data
          name: redis-data
        - mountPath: /etc/redis/redis.cof
          name: rediscnf
          subPath: redis.cof
      volumes:
      - name: redis-data
        persistentVolumeClaim:
          claimName: pv-redis
      - name: rediscnf
        configMap:
          name: rediscnf
      imagePullSecrets:
      - name: my-harbor
---
kind: Service
apiVersion: v1
metadata:
  name: redis
  namespace: redis-pub
  labels:
    name: redis
spec:
 type: NodePort
 ports:
 - port: 6379
   targetPort: 6379
   nodePort: 30041
   name: redis-port
 selector:
   name: redis

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
 name: pv-redis
 namespace: redis-pub
spec:
 accessModes:
   - ReadWriteMany
 resources:
   requests:
     storage: 300Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: rediscnf
  namespace: redis-pub
data:
  redis.cof: |
    bind 0.0.0.0
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 0
    #loglevel notice
    #logfile "/redis/logs/redis.log"
    databases 16
    requirepass liubei@2021


在这里插入图片描述

posted on 2021-08-16 23:01  运维开发玄德公  阅读(23)  评论(0编辑  收藏  举报  来源

导航