vim redis.yml
apiVersion: v1
kind: Namespace
metadata:
name: lamp-cloud-k8s
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis
namespace: lamp-cloud-k8s
labels:
name: redis
spec:
replicas: 1
selector:
matchLabels:
name: redis
template:
metadata:
labels:
name: redis
spec:
containers:
- name: redis
image: redis:5.0.5
volumeMounts:
- name: redis-config
mountPath: "/usr/local/etc/redis"
- name: redis-data
mountPath: "/data"
command:
- "redis-server"
args:
- "/usr/local/etc/redis/redis.conf"
volumes:
- name: redis-config
hostPath:
path: /data/lamp-cloud-k8s/redis-config
type: DirectoryOrCreate
- name: redis-data
hostPath:
path: /data/lamp-cloud-k8s/redis-data
type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
name: redis
namespace: lamp-cloud-k8s
labels:
name: redis
spec:
type: NodePort # 如果需要集群外部访问,这里改为NodePort
ports:
- port: 6379
protocol: TCP
targetPort: 6379
name: redis
nodePort: 32379
selector:
name: redis
vim redis.conf
vim /data/lamp-cloud-k8s/redis-config/redis.conf
requirepass SbtyMveYNfLzTks7H0apCmyStPzWJqjy
bind 0.0.0.0
save 900 1
save 300 10
save 60 10000
创建redis
kubectl create -f redis.yml
|