节点红色Kubernetes部署

hmae6n7t  于 2022-12-17  发布在  Kubernetes
关注(0)|答案(2)|浏览(184)

我尝试在kubernetes本地部署一个简单的node-red容器,以监控其使用情况,同时创建一个持久卷存储,以便保存我的node-red工作。但是,我无法将其部署到kubernetes。

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nodered
  name: nodered
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nodered
  template:
    metadata:
      labels:
        app: nodered
    spec:
      containers:
      - name: nodered
        image: nodered/node-red:latest
        limits:
        memory: 512Mi
        cpu: "1"
      requests:
        memory: 256Mi
        cpu: "0.2"
        ports:
        - containerPort: 1880
        volumeMounts:
        - name: nodered-claim
          mountPath: /data/nodered
          # subPath: nodered <-- not needed in your case
      volumes:
      - name: nodered-claim
        persistentVolumeClaim:
          claimName: nodered-claim
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: small-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
  - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: local-storage
  local:
    path: /data
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: kubernetes.io/hostname
          operator: In
          values:
          - minikube
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nodered-claim
spec:
  storageClassName: local-storage
  accessModes:
    - ReadWriteOnce
  resources:
    requests:enter image description here
      storage: 1Gi
---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: Immediate

我在powershell中得到这个错误:

kubectl apply -f ./Deployment.yaml
persistentvolume/small-pv unchanged
persistentvolumeclaim/nodered-claim unchanged
storageclass.storage.k8s.io/local-storage unchanged
Error from server (BadRequest): error when creating "./Deployment.yaml": Deployment in version "v1" cannot be handled as a Deployment: strict decoding error: unknown field "spec.template.spec.containers[0].cpu", unknown field "spec.template.spec.containers[0].limits", unknown field "spec.template.spec.containers[0].memory", unknown field "spec.template.spec.requests"

我希望将其部署到kubernetes,以便可以监视nodered容器的内存使用情况

s2j5cfk0

s2j5cfk01#

requestslimits部分需要位于resources标题下,如下所示:

spec:
      containers:
      - name: nodered
        image: nodered/node-red:latest
        resources:
          limits:
            memory: 512Mi
            cpu: "1"
          requests:
            memory: 256Mi
            cpu: "0.2"
        ports:
        - containerPort: 1880
        volumeMounts:
        - name: nodered-claim
          mountPath: /data/nodered
          # subPath: nodered <-- not needed in your case
n7taea2i

n7taea2i2#

您的部署存在语法错误。让我们将其修复为正确的syntax
应该是这样的:

containers:
  - name: nodered
    image: nodered/node-red:latest
    resources:
      requests:
        memory: "256Mi"
        cpu: "0.2"
      limits:
        memory: "512Mi"
        cpu: "1"

相关问题