一、configmap
# cat redis-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:name: redis-single-confignamespace: redis
data:redis.conf: |daemonize nobind 0.0.0.0port 6379tcp-backlog 511timeout 0tcp-keepalive 300pidfile /data/redis-server.pidlogfile /data/redis.logloglevel noticedatabases 16always-show-logo yessave 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /dataslave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100appendonly yesappendfilename "appendonly.aof"appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events ""hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size -2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yesrequirepass 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-singlenamespace: redis
spec:replicas: 1selector:matchLabels:app: redis-singletemplate:metadata:labels:app: redis-singlespec:initContainers:- name: init-0image: busyboximagePullPolicy: IfNotPresentterminationMessagePath: /dev/termination-logterminationMessagePolicy: Filecommand: [ "sysctl", "-w", "net.core.somaxconn=511" ]securityContext:privileged: true- name: init-1image: busyboximagePullPolicy: IfNotPresentterminationMessagePath: /dev/termination-logterminationMessagePolicy: Filecommand: [ "sh", "-c", "echo never > /sys/kernel/mm/transparent_hugepage/enabled" ]securityContext:privileged: truecontainers:- name: redis-singleimage: redis:6.0.8imagePullPolicy: IfNotPresentterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- name: redis-datamountPath: /data- name: redis-configmountPath: /usr/local/etc/redis/redis.confsubPath: redis.confcommand: [ "redis-server" ,"/usr/local/etc/redis/redis.conf" ]env:- name: TZvalue: "Asia/Shanghai"volumes:- name: timezonehostPath:path: /usr/share/zoneinfo/Asia/Shanghai- name: redis-datanfs:path: /nfs/redisserver: 192.168.110.38- name: redis-configconfigMap:name: redis-single-configitems:- key: redis.confpath: redis.conf
# kubectl apply -f redis-deployment.yaml
三、service编写
# cat redis-service.yaml
apiVersion: v1
kind: Service
metadata:name: service-redis-singlenamespace: redislabels:app: redis-single
spec:selector:app: redis-singleports:- name: redis-singleport: 6379targetPort: 6379nodePort: 30000type: NodePort# kubectl apply -f redis-service.yaml
service/service-redis-single created