skip to Main Content

I am trying to run a test container through the Kubernetes but I got error. The below is my deploy.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.22.0 (955b78124)
  creationTimestamp: null
  labels:
    io.kompose.service: nginx
  name: nginx
spec:
  containers:
      requests:
          storage: 2Gi
          cpu: 0.5
          memory: "128M"
      limits:
          cpu: 0.5
          memory: "128M" # This is the line throws error
          - type: PersistentVolumeClaim
          max:
            storage: 2Gi
          min:
            storage: 1Gi
.
.
.

When I run kubectl apply -k ., I get this error:

error: accumulating resources: accumulation err='accumulating resources from 'deploy.yaml': yaml: line 19: did not find expected key': got file 'deploy.yaml', but '/home/kus/deploy.yaml' must be a directory to be a root

I tried to read the Kubernetes but I cannot understand why I’m getting error.

Edit 1

I changed my deploy.yaml file as @whites11 said, now it’s like:

.
.
.
spec:
  limits:
    memory: "128Mi"
    cpu: 0.5
.
.
.

Now I’m getting this error:

resourcequota/storagequota unchanged
service/nginx configured
error: error validating ".": error validating data: ValidationError(Deployment.spec): unknown field "limits" in io.k8s.api.apps.v1.DeploymentSpec; if you choose to ignore these errors, turn validation off with --validate=false

2

Answers


  1. The file you shared is not valid YAML.

    limits:
         cpu: 0.5
         memory: "128M" # This is the line throws error
         - type: PersistentVolumeClaim
         max:
           storage: 2Gi
         min:
           storage: 1Gi
    

    The limits field has mixed type (hash and collection) and is obviously wrong.

    Seems like you took the syntax for specifying pods resource limits and mixed it with the one used to limit storage consuption.

    In your Deployment spec you might want to set limits simply like this:

    apiVersion: apps/v1
    kind: Deployment
    ...
    spec:
      ...
      template:
      ...
        spec:
          containers:
          - ...
            resources:
              limits:
                cpu: 0.5
                memory: "128M"
    

    And deal with storage limits at the namespace level as described in the documentation.

    Login or Signup to reply.
  2. You should change your yaml file to this:

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx
      labels:
        name: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search