通过Config Map来对容器中redis应用的配置进行管理,如自定义配置文件、密码、日志路径等。

创建一个namespace

接下来的pod,svc都建到这个namespace下

kubectl create namespace devops

创建redis.conf对应的ConfigMap文件

touch redis-config.yaml

---

kind: ConfigMap

apiVersion: v1

metadata:

name: redis-config

labels:

app: redis

data:

redis.conf: |-

dir /srv

port 6379

bind 0.0.0.0

appendonly yes

daemonize no

#protected-mode no

requirepass Hangzhou@123

pidfile /srv/redis-6379.pid

requirepass Hangzhou@123 这个密码记住,登录的时候需要用。

更新/创建在yaml中定义的对象

kubectl apply -f redis-config.yaml -n devops

创建持久化文件

touch redis-deploy.yaml

---

apiVersion: apps/v1

kind: Deployment

metadata:

name: redis

labels:

app: redis

spec:

replicas: 1

selector:

matchLabels:

app: redis

template:

metadata:

labels:

app: redis

spec:

containers:

- name: redis

image: redis:3.0.7

command:

- "sh"

- "-c"

- "redis-server /usr/local/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: config

mountPath: /usr/local/redis/redis.conf

subPath: redis.conf

volumes:

- name: config

configMap:

name: redis-config

创建configmap和deployment

kubectl apply -f redis-config.yaml --force -n devops

kubectl apply -f redis-deploy.yaml -n devops --force

创建对外访问服务svc

touch redis-svc.yaml

apiVersion: v1

kind: Service

metadata:

name: redis

namespace: devops

labels:

app: redis

spec:

type: NodePort

ports:

- name: tcp

port: 6379

nodePort: 30379

selector:

app: redis

更新/创建在yaml中定义的对象

kubectl apply -f redis-svc.yaml -n devops

查询一下端口

kubectl get svc -n devops

去web仪表盘看一下:

推荐文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: