Kubernetes create namespace with default quotas

Posted by

Yesterday I posted a blog article around how to create a new namespace for a new deployment and apply quotas.  However, I immediately got several requests around is there an easier way to do this or apply quotas at the namespace level for all future pod creations. 

Personal best practice; I like creating a yaml file for everything when I can.  This way it is easy to transition to other engineers and if you need to make an edit to task it won’t possibly effect other variables inside the config file that may not be related to your change.

Article from yesterday:

How to set defaults at namespace level

Apply the two yaml files

$ kubectl describe limits limits –namespace=<namespace>

This will show you the default limits on the namespace now

This means when you deploy a deployment it will be using the defaults

apiVersion: apps/v1
kind: Deployment
  name: helloworld-deployment
  namespace: namespace-demo
  replicas: 3
      app: helloworld
        app: helloworld
      - name: k8s-demo
        image: vmpebryant/k8s-demo
        - name: nodejs-port
          containerPort: 3000

Deploy the helloworld config file

As you may note from the previous blog article we have not specified the quotas in this config file

As you can see the three expected pods were deployed in the namespace

$ kubectl describe pod <pod> –namespace=<namespace>

Just to confirm the limits for the pod.

Just by creating one additional config file we are able to set new default limits for resources on this namespace.  As always, I hope y’all found this helpful.

Leave a Reply