Configure Applications

Learn how to put the latest open source technology into practice with hands-on training, delivered by industry experts, aligned to your desired business outcomes

There are several ways to configure applications running under Kubernetes. One way is to change the command and arguments running in the container using the command and args arrays in a yaml file:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: busybox
  name: busybox
spec:
  containers:
  - command:
    - /bin/sh
    args:
    - -c
    - tail -f /dev/null
    image: busybox
    name: busybox

Application configurations and credentials can be stored in the cluster as ConfigMap or Secret resources. Containers running in pods can consume ConfigMaps and Secrets as volumes or environment variables. ConfigMaps can be created from literal key-value pairs or from files. Below, we create a ConfigMap from a redis configuration file on disk:

$ cat redis.conf

bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300

$ kubectl create configmap --from-file redis.conf redisconf

configmap/redisconf created

$ kubectl describe configmap redisconf

Name:         redisconf
Namespace:    default
Labels:       
Annotations:  

Data
====
redis.conf:
----
bind 127.0.0.1
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300

Events:  

$

The redis.conf file is now available for any pod to use and mount. ConfigMaps are a good way to make common configuration files available to applications running anywhere in a Kubernetes cluster. The example below shows a pod that runs redis using the redis.conf file stored as a ConfigMap:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: redis-dev
  name: redis-dev
spec:
  containers:
  - command:
    - redis-server
    - /config/redis.conf
    image: redis
    name: redis-dev
    volumeMounts:
    - name: redis
      mountPath: /config
  volumes:
  - name: redis
    configMap:
      name: redisconf 
  restartPolicy: OnFailure

Learn more about configuring applications using ConfigMaps
Learn how to influence container commands