Kubernetes create namespace with default quotas

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

Screenshot from the Create a Kubernetes Namespace With Default Quotas walkthrough at step 1, showing namespace/namespace-demo created; the adjacent article text explains that how to set defaults at namespace level.

Apply the two yaml files

Screenshot from the Create a Kubernetes Namespace With Default Quotas walkthrough at step 2; the step instructs the user to 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

Screenshot from the Create a Kubernetes Namespace With Default Quotas walkthrough at step 3, showing kind: Deployment; the adjacent article text explains that this means when you deploy a deployment it will be using the defaults.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: helloworld-deployment
  namespace: namespace-demo
spec:
  replicas: 3
  selector:
    matchLabels:
      app: helloworld
  template:
    metadata:
      labels:
        app: helloworld
    spec:
      containers:
      - name: k8s-demo
        image: vmpebryant/k8s-demo
        ports:
        - name: nodejs-port
          containerPort: 3000

Screenshot from the Create a Kubernetes Namespace With Default Quotas walkthrough at step 4, showing containerPort: 3000; the adjacent article text explains that this will show you the default limits on the namespace now.

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

Screenshot from the Create a Kubernetes Namespace With Default Quotas walkthrough at step 5, showing hel loword-deployment-6676687669-b22Fc; the adjacent article text explains the kubectl describe pod command with pod and namespace placeholders.

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

Just to confirm the limits for the pod.

Summary:
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.

Keep exploring

Choose your next step

Continue with the path that best matches the architecture or operating challenge in front of you.

1 thought on “Kubernetes create namespace with default quotas”

Leave a Reply

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading