Home > database >  Node-red Kubernetes Deployment
Node-red Kubernetes Deployment

Time:12-16

I am trying to deploy a simple node-red container on kubernetes locally to monitor its usage and at the same time create a persistent volume storage so that my node red work is saved. However, I can't get it to deploy to kubernetes. I have created a Deployment.yaml file with the following code

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

I am getting this error in 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"

I want it to deploy to kubernetes so that I can monitor the memory usage of the node red container

CodePudding user response:

The requests & limits sections needs to be under a resources heading as follows:

    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

CodePudding user response:

Your deployment was syntax error. Let's fix it to the right syntax

It should be like this:

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