Azure
Software Deployment On Azure Kubernetes Service – Half Two
Introduction
What we are going to cowl on this article:
- What’s ConfigMap?
- Redis grasp with a ConfigMap
- Making a ConfigMap from a file
- Making a ConfigMap from a YAML file
- Utilizing a ConfigMap to learn in configuration knowledge
Conditions
Within the earlier article of Software Deployment on AKS half 1, you examined the Redis grasp deployment you created. You noticed how a deployment pertains to a ReplicaSet and the way a ReplicaSet pertains to Pods. On this half 2, you’ll recreate this Redis grasp with an environment-specific configuration supplied through a ConfigMap. However first, let’s discover what a ConfigMap is.
What’s ConfigMap?
Additionally, you will edit the pattern functions to offer configuration particulars utilizing a ConfigMap. A ConfigMap is an object that’s used to offer configuration particulars to Pods. It permits you to preserve configuration settings exterior of the particular container. You may then present these configuration particulars to your utility by connecting the ConfigMap to your deployment.
Redis grasp with a ConfigMap
There was nothing improper with the earlier deployment. In sensible use instances, it might be uncommon that you’d launch an utility with out some configuration settings. On this case, we’re going to set the configuration settings for redis-master utilizing a ConfigMap. A ConfigMap is a conveyable method of configuring containers with out having specialised photographs for every configuration. It has a key-value pair for knowledge that must be set on a container. A ConfigMap is used for non-secret configuration. Kubernetes has a separate object referred to as a Secret. A Secret is used for configurations that comprise vital knowledge resembling passwords.
On this instance, we’re going to create a ConfigMap. On this ConfigMap, we are going to configure redis-config as the important thing and the worth might be:
- maxmemory 2mb
- maxmemory-policy allkeys-lru
Now, let’s create this ConfigMap. There are two methods to create a ConfigMap:
- Making a ConfigMap from a file
- Making a ConfigMap from a YAML file
We are going to discover every one intimately.
Making a ConfigMap from a file
The next steps will assist us create a ConfigMap from a file:
Step 1
Open the Azure Cloud Shell code editor by typing code redis-config within the terminal. Copy and paste the next two traces and put it aside as redis-config,
- maxmemory 2mb
- maxmemory-policy allkeys-lru

Step 2
Now you’ll be able to create the ConfigMap utilizing the next code:
- kubectl create configmap example-redis-config –from-file=redis-config
It’s best to get an output as proven beneath:
- configmap/example-redis-config created

Step 3
You need to use the identical command to explain this ConfigMap:
- kubectl describe configmap/example-redis-config
The output might be as proven within the screenshot beneath:

Making a ConfigMap from a YAML file
On this part, you’ll recreate the ConfigMap from the earlier part utilizing a YAML file.
Step 1
To start out, delete the beforehand created ConfigMap:
- kubectl delete configmap/example-redis-config

Step 2
Copy and paste the next traces right into a file named example-redis-config.yaml, after which save the file:
- apiVersion: v1
- knowledge:
- redis-config: |-
- maxmemory 2mb
- maxmemory-policy allkeys-lru
- sort: ConfigMap
- metadata:
- title: example-redis-config
- namespace: default
Step 3
Now you can recreate your ConfigMap through the next command:
- kubectl create -f example-redis-config.yaml
It’s best to get an output as proven beneath:
- configmap/example-redis-config created

Step 5
This command returns the identical output because the earlier one.
As you’ll be able to see, utilizing a YAML file, you had been in a position to create the identical ConfigMap.
Notice
kubectl get has the helpful possibility -o, which can be utilized to get the output of an object in both YAML or JSON. That is very helpful in instances the place you could have made guide adjustments to a system and wish to see the ensuing object in YAML format. You may get the present ConfigMap in YAML utilizing the next command:
- kubectl get -o yaml configmap/example-redis-config

Now that you’ve got the ConfigMap outlined, let’s use it.
Utilizing a ConfigMap to learn in configuration knowledge
On this part, you’ll reconfigure the redis-master deployment to learn configuration from the ConfgMap.
Step 1
To start out, modify redis-master-deployment.yaml to make use of the ConfigMap as follows. The adjustments you’ll want to make might be defined after the supply code.
Notice
When you downloaded the supply code from GitHub, there’s a file within the deployment folder: Software deployment on AKS, referred to as redis-master-deployment_ Modified.yaml, which has the required adjustments utilized to it.
- apiVersion: apps/v1 # for variations earlier than 1.9.0 use apps/v1beta2
- sort: Deployment
- metadata:
- title: redis-master
- labels:
- app: redis
- spec:
- selector:
- matchLabels:
- app: redis
- function: grasp
- tier: backend
- replicas: 1
- template:
- metadata:
- labels:
- app: redis
- function: grasp
- tier: backend
- spec:
- containers:
- – title: grasp
- picture: k8s.gcr.io/redis:e2e
- command:
- – redis-server
- – “/redis-master/redis.conf”
- env:
- – title: MASTER
- worth: “true”
- volumeMounts:
- – mountPath: /redis-master
- title: config
- assets:
- requests:
- cpu: 100m
- reminiscence: 100Mi
- ports:
- – containerPort: 6379
- volumes:
- – title: config
- configMap:
- title: example-redis-config
- objects:
- – key: redis-config
- path: redis.conf
Let’s dive deeper into the code to grasp the completely different sections,
Strains 24-26
These traces introduce a command that might be executed when your Pod begins. On this case, this can begin the redis-server pointing to a particular configuration file.
- command:
- – redis-server
- – “/redis-master/redis.conf”
Strains 27-29
- env:
- – title: MASTER
- worth: “true”
Strains 30-32
- volumeMounts:
- – mountPath: /redis-master
- title: config
Line 40
Strains 41-42
- configMap:
- title: example-redis-config
Strains 43-45
- objects:
- – key: redis-config
- path: redis.conf
Step 2
Let’s create this up to date deployment:
- kubectl create -f redis-master-deployment_Modified.yml
This could output the next:
- deployment.apps/redis-master created

Step 3
Let’s now be sure that the configuration was efficiently utilized. First, get the Pod’s title:

Step 4
Then exec into the Pod and confirm that the settings had been utilized:
- kubectl exec -it redis-master-<pod-id> redis-cli
- 127.0.0.1:6379> CONFIG GET maxmemory
- 1) “maxmemory” 2) “2097152”
- 127.0.0.1:6379> CONFIG GET maxmemory-policy
- “maxmemory-policy”
- “allkeys-lru” 127.0.0.1:6379>exit

To summarize, you could have simply carried out an necessary and difficult a part of configuring cloud-native functions. You should have additionally observed that the apps should be configured to learn config dynamically. After you arrange your app with configuration, you accessed a operating container to confirm the operating configuration.
On this half 2, you configured the Redis Grasp to load configuration knowledge from a ConfigMap. Within the subsequent last half 3, we are going to deploy the end-to-end utility.