NashTech Blog

OpenKruise: Namespaced Resource Management

Table of Contents
gray and black hive printed textile

In this blog, we will see how OpenKruise helps us in enriching the capability of Kubernetes by managing the Kubernetes resources.

In Kubernetes, resources such as Secrets and ConfigMaps scoped to specific namespaces might need to be shared of synchronized across multiple namepsaces. However, the native capabilities of Kubernetes do not inherently support an automated way to distribute or synchronize these resources across different namespaces. This limitation results in users having to manually perform the distribution and synchronication of each resource, one by one, which can be cumbersome and time-consuming, especially in environments with numerous namespaces or frequent resource updates.

Recognising the inconvenience and need for a more automated solution, we will make use of ResourceDistribution. This tool has been specifically crafted to cater to scenarios where seamless and automated distribution of resources across namespaces is essential. ResourceDistribution acts as a bridge to fill the gap left by Kubernetes native capabilities. It automates the process of distributing and synchronizing resources, eliminating the need for manual intervention adn streamlining the management of Secrets and ConfigMaps across multiple namespaces.

At its current stage, ResourceDistribution focuses on providing robust support for 2 crucial Kubernetes resources: Secrets and ConfigMaps. It simplifies the intricate task of ensuring that these resources are consistently distributed and synchronized across the designated namespaces, promoting ease of management and ensuring uniformity across the cluster. By utilizing Resource Distribution, Kubernetes users can significantly reduce the overhead involved in managing these resources across namespaces, allowing them to focus more on higher-level tasks and ensuring smoother operations within their Kubernetes environment.

Creating a Resource Distribution YAML

Consider a scenario. You have multiple application deployment in different namespaces. All these applications require values of certain environment variables to access and query a database. Since these applications are on different namespaces, we would require configmap in place for application to fetch the necessary data from. Here, instead of creating configmap in multiple different namespaces, we will utilize ResourceDistribution feature of OpenKruise to deploy the configmaps in the namespaces our applications are present in.

Scenario 1

Our applications are deployed in app1, app2, app3 namespaces.

Create a Resource Distribution yaml file. This file will contain the configmap data and the target will be set to the namespaces we want to deploy the configmap in.

apiVersion: apps.kruise.io/v1alpha1
kind: ResourceDistribution
metadata:
name: database-rd
spec:
resource:
apiVersion: v1
kind: ConfigMap
metadata:
name: database-cm
data:
DATABASE_URL: https://<DB-URL>
  ENVIRONMENT: development
  DATABASE_USER: knoldus
targets:
includedNamespaces:
list:
– name: app1
  - name: app2
– name: app3

First lets begin by creating these two namespaces: app1 and app2

kubectl create ns app1
kuebctl create ns app2

Apply the Resource Distribution file.

kubectl apply -f rdcm.yaml

Check if the config maps have been created or not.

kubectl get cm -n app1
kubectl get cm -n app2

Check the cm resource in app3 namespace.

kubectl get cm -n app3

Since app3 namespace has not been created yet, you will find no resource in app3 namespace. Now lets create app3 namespace.

kubectl create ns app3

Check if the configmap is created or not.

kubectl get cm -n app3

With the creation of the namespace, the resource definition also gets created.

Scenario 2

We need the resource in every namespace that has label environment=dev

apiVersion: apps.kruise.io/v1alpha1
kind: ResourceDistribution
metadata:
name: database-rd
spec:
resource:
apiVersion: v1
kind: ConfigMap
metadata:
name: database-cm
data:
DATABASE_URL: https://<DB-URL>
  ENVIRONMENT: development
  DATABASE_USER: knoldus
targets:
 namespaceLabelSelector:
matchLabels:
environment: dev

Scenario 3

We need to exclude certain namespaces which have the label environment=dev

apiVersion: apps.kruise.io/v1alpha1
kind: ResourceDistribution
metadata:
name: database-rd
spec:
resource:
apiVersion: v1
kind: ConfigMap
metadata:
name: database-cm
data:
DATABASE_URL: https://<DB-URL>
  ENVIRONMENT: development
  DATABASE_USER: knoldus
targets:
 excludedNamespaces:
  list:
  - name: app3
 namespaceLabelSelector:
matchLabels:
environment: dev

This will deploy the resource in every namespace that has the label environment=dev excluding app3 namespace.

Hey, readers! Thank you for sticking up till the end. This was a brief on Resource Management by OpenKruise. If you have any questions/feedbacks regarding this blog, I am reachable at vidushi.bansal@nashtechglobal.com. You can find more of my blogs here.

Search

Proudly powered by WordPress

Picture of Vidushi Bansal

Vidushi Bansal

Vidushi Bansal is a Sr. Software Consultant [Devops] at Knoldus Inc | Path of Nashtech. She is passionate about learning and exploring new technologies.

Leave a Comment

Your email address will not be published. Required fields are marked *

Suggested Article

Scroll to Top