k8s部署单节点redis

原文

1.部署configmap

redis-config.yaml

---
kind: ConfigMap
apiVersion: v1
metadata:
  name: redis-config
  namespace: dev
  labels:
    app: redis
data:
  redis.conf: |-
    dir /srv
    port 6379
    bind 0.0.0.0
    appendonly yes
    daemonize no
    #protected-mode no
    requirepass 123456
    pidfile /srv/redis-6379.pid

创建

kubectl create -f redis-config.yaml

如果redis数据需要持久化 可以用存储

2.部署deploy

redis-deploy.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  namespace: dev
  labels:
    app: redis
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis
  template:
    metadata:
      labels:
        app: redis
    spec:
      containers:
      - name: redis
        image: redis:5.0.8
        command:
          - "sh"
          - "-c"
          - "redis-server /usr/local/redis/redis.conf"
        ports:
        - containerPort: 6379
        resources:
          limits:
            cpu: 100m
            memory: 100Mi
          requests:
            cpu: 50m
            memory: 30Mi
        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

创建

kubectl create -f redis-deploy.yaml

测试

# 查看pod的ip
kubectl get pods -n dev -o wide
# 运行一个自删除的redis 容器 测试pod的连通性
docker run -it  --rm  redis:3.0.7 /bin/bash
# 或者
kubectl exec -it -n dev redis-99c765c65-7xp7g -- bash
root@redis-99c765c65-7xp7g:/data# redis-cli 
127.0.0.1:6379> auth 123456 

# 使用reids-cli命令连接测试

3.部署service

redis-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: redis-service
  namespace: dev
  labels:
    app: redis
spec:
  type: NodePort
  ports:
    - name: tcp
      port: 6379
  selector:
    app: redis

创建

kubectl create -f redis-service.yaml

然后外部连接测试

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值