k8s部署单节点redis

一、configmap

复制代码
# cat redis-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-single-config
  namespace: redis
data:
  redis.conf: |
    daemonize no
    bind 0.0.0.0
    port 6379
    tcp-backlog 511
    timeout 0
    tcp-keepalive 300
    pidfile /data/redis-server.pid
    logfile /data/redis.log
    loglevel notice
    databases 16
    always-show-logo yes
    save 900 1
    save 300 10
    save 60 10000
    stop-writes-on-bgsave-error yes
    rdbcompression yes
    rdbchecksum yes
    dbfilename dump.rdb
    dir /data
    slave-serve-stale-data yes
    slave-read-only yes
    repl-diskless-sync no
    repl-diskless-sync-delay 5
    repl-disable-tcp-nodelay no
    slave-priority 100
    appendonly yes
    appendfilename "appendonly.aof"
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb
    aof-load-truncated yes
    lua-time-limit 5000
    slowlog-log-slower-than 10000
    slowlog-max-len 128
    latency-monitor-threshold 0
    notify-keyspace-events ""
    hash-max-ziplist-entries 512
    hash-max-ziplist-value 64
    list-max-ziplist-size -2
    list-compress-depth 0
    set-max-intset-entries 512
    zset-max-ziplist-entries 128
    zset-max-ziplist-value 64
    hll-sparse-max-bytes 3000
    activerehashing yes
    client-output-buffer-limit normal 0 0 0
    client-output-buffer-limit slave 256mb 64mb 60
    client-output-buffer-limit pubsub 32mb 8mb 60
    hz 10
    aof-rewrite-incremental-fsync yes
    requirepass redis#s

kubectl create namespace redis

kubectl apply -f redis-configmap.yaml

二、deployment编写

复制代码
# cat redis-deployment.yaml 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-single
  namespace: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-single
  template:
    metadata:
      labels:
        app: redis-single
    spec:
      initContainers:
        - name: init-0
          image: busybox
          imagePullPolicy: IfNotPresent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          command: [ "sysctl", "-w", "net.core.somaxconn=511" ]
          securityContext:
            privileged: true
        - name: init-1
          image: busybox
          imagePullPolicy: IfNotPresent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          command: [ "sh", "-c", "echo never > /sys/kernel/mm/transparent_hugepage/enabled" ]
          securityContext:
            privileged: true
      containers:
        - name: redis-single
          image: redis:6.0.8
          imagePullPolicy: IfNotPresent
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - name: redis-data
              mountPath: /data
            - name: redis-config
              mountPath: /usr/local/etc/redis/redis.conf
              subPath: redis.conf
          command: [ "redis-server" ,"/usr/local/etc/redis/redis.conf" ]
          env:
            - name: TZ
              value: "Asia/Shanghai"
      volumes:
        - name: timezone
          hostPath:
            path: /usr/share/zoneinfo/Asia/Shanghai
        - name: redis-data
          nfs:
            path: /nfs/redis
            server: 192.168.110.38
        - name: redis-config
          configMap:
            name: redis-single-config
            items:
              - key: redis.conf
                path: redis.conf

kubectl apply -f redis-deployment.yaml

三、service编写

复制代码
# cat redis-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: service-redis-single
  namespace: redis
  labels:
    app: redis-single
spec:
  selector:
    app: redis-single
  ports:
    - name: redis-single
      port: 6379
      targetPort: 6379
      nodePort: 30000
  type: NodePort


# kubectl apply -f redis-service.yaml
service/service-redis-single created

四、测试

相关推荐
八股文领域大手子3 小时前
Leetcode32 最长有效括号深度解析
java·数据库·redis·sql·mysql
Hurry63 小时前
Rocky Linux 9.x 基于 kubeadm部署k8s 1.32
linux·运维·kubernetes
zhuyasen4 小时前
在Go语言中的Redis缓存与本地内存缓存实战示例
redis·go·memcached
java干货仓库6 小时前
Redisson 加锁和释放锁底层是怎么实现的?
java·redis
Honmaple6 小时前
Redis 三主三从集群部署的完整方案
数据库·redis·缓存
C语言小火车6 小时前
Redis 10大核心场景实战手册:从缓存加速到分布式锁的全面解析
c语言·开发语言·数据库·c++·redis
沐风清扬7 小时前
Redis-分布式锁实现秒杀
数据库·redis·分布式·缓存·php
kyle~8 小时前
docker
运维·docker·容器
姚毛毛-aione1.com8 小时前
【k8s003】k8s与docker的依赖关系
docker·容器·kubernetes
皮卡兔子屋10 小时前
redis过期删除、内存淘汰、双写一致性---java
java·redis·mybatis