k8s部署redis单节点
创建pvc.yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: nfspvc1 namespace: sqqqq spec: accessModes: - ReadWriteOnce resources: requests: storage: 5Gi storageClassName: nfs-storage
创建redis-configmap.yaml kind: ConfigMap apiVersion: v1 metadata: name: redis-config namespace: sqqqqqq labels: app: redis data: redis.conf: |- dir /data port 6379 bind 0.0.0.0 appendonly yes protected-mode no requirepass 123456 pidfile /data/redis-6379.pid
创建redis-StatefulSet.yaml --- apiVersion: v1 kind: Service metadata: name: redis namespace: sqqqqqqq labels: app: redis spec: type: NodePort ports: - name: redis port: 6379 protocol: TCP targetPort: 6379 nodePort: 30079 selector: app: redis --- apiVersion: apps/v1 kind: Deployment metadata: name: redis namespace: sqqqqqqq labels: app: redis spec: replicas: 1 selector: matchLabels: app: redis template: metadata: labels: app: redis spec: # 进行初始化操作,修改系统配置,解决 Redis 启动时提示的警告信息 initContainers: - name: system-init image: busybox:1.32 imagePullPolicy: IfNotPresent command: - "sh" - "-c" - "echo 2048 > /proc/sys/net/core/somaxconn && echo never > /sys/kernel/mm/transparent_hugepage/enabled" securityContext: privileged: true runAsUser: 0 volumeMounts: - name: sys mountPath: /sys containers: - name: redis image: redis:4.0 command: - "sh" - "-c" - "redis-server /usr/local/etc/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: data mountPath: /data - name: config mountPath: /usr/local/etc/redis/redis.conf subPath: redis.conf imagePullSecrets: - name: xxxxxxx # 镜像仓库 volumes: - name: data persistentVolumeClaim: claimName: nfspvc1 - name: config configMap: name: redis-config - name: sys hostPath: path: /sys
作者:南辞、归
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
博主的文章没有高度、深度和广度,只是凑字数。由于博主的水平不高,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、抄袭、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个无耻的文档搬运工!