首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用kubectl应用yaml在Kubernetes中设置Maxmemory和Maxmemory策略

使用kubectl应用yaml在Kubernetes中设置Maxmemory和Maxmemory策略
EN

Stack Overflow用户
提问于 2020-03-04 03:06:44
回答 1查看 764关注 0票数 0

有没有一种方法可以在Kubernetes上为Redis设置maxmemory和maxmemory策略?

我使用的命令kubectl应用-f redis-cache.yaml

文件redis-cache.yaml包含以下内容:

代码语言:javascript
复制
apiVersion: apps/v1
data:
  redis-config: |
    maxmemory 256
    maxmemory-policy allkeys-lru
kind: Deployment
metadata:
  name: redis-cache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-cache
  template:
    metadata:
      labels:
        app: redis-cache
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      containers:
      - name: redis-cache
        image: redis
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 150m
            memory: 256Mi
        ports:
        - containerPort: 6379
          name: redis
---
apiVersion: v1
kind: Service
metadata:
  name: redis-cache
spec:
  ports:
  - port: 6379
  selector:
    app: redis-cache
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-04 04:56:14

Kubernetes deployment没有名为data的字段。

您可以通过ConfigMapSecret提供配置。Redis配置文件位于installdir/redis/etc/redis.conf

ConfigMap:

代码语言:javascript
复制
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-config
data:
  redis.conf: |-
    maxmemory 256
    maxmemory-policy allkeys-lru

部署:

代码语言:javascript
复制
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis-cache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: redis-cache
  template:
    metadata:
      labels:
        app: redis-cache
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      volumes:
      - name: redis-config
        configMap:
          name: redis-config
      containers:
      - name: redis-cache
        image: redis
        volumeMounts:
        - name: redis-config
          mountPath: /redis/etc
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 150m
            memory: 256Mi
        ports:
        - containerPort: 6379
          name: redis
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60518500

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档