Configuration in Kubernetes

Kubernetes offers a container-centric management environment, orchestrating the computing, network, and storage infrastructure, so that user workloads don’t have to orchestrate that.

Kubernetes was designed as a platform to build an ecosystem of components and tools that make it easier to deploy, scale, and manage applications. The information is often provided as a «.yaml» file.

In the .yaml file of the Kubernetes object that you want to create, you must necessarily indicate the following values ​​of the fields (at least):

  • apiVersion: which version of the Kubernetes API you are using to create this object.
  • kind: what kind of object you want to create.
  • metadata: data that uniquely identifies the object, including a text string for the name, UID, and optionally the namespace.

You must also specify the object’s «spec» field. The format of this field is different depending on the type of Kubernetes object, and it contains nested fields that are specific to each object.

In order to see how the distributed logs work, you will have to create an instance of Elasticsearch, Fluentd and Grafana. To check its operation, you will use a microservice, including the option to configure the output logs to Fluentd.

Next, we will explain the version and configuration used by each of these technologies:

Elasticsearch

In this case, we will use the instance provided by the Onesait platform

Fluentd

An image with version v1.4.2-2.0 has been created and is available on Azure at: solutionsregistry.azurecr.io/architecture/fluentd:v1.4.2-2.0.

Next, we will detail the necessary files for its configuration in OpenShift:

fluentd.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
annotations:
deployment.kubernetes.io/revision: ‘9’
namespace: <NAMESPACE>
labels:
app: fluentd
group: onesait-efg
spec:
replicas: 1
selector:
matchLabels:
app: fluentd
template:
metadata:
creationTimestamp: null
labels:
app: fluentd
spec:
volumes:
– name: config-file
configMap:
name: fluentd-config-map
defaultMode: 484
containers:
– resources:
limits:
cpu: 300m
memory: 1Gi
requests:
cpu: 100m
memory: 500Mi
terminationMessagePath: /dev/termination-log
name: fluentd
ports:
– name: 24224tcp24224
containerPort: 24224
protocol: TCP
imagePullPolicy: Always
volumeMounts:
– name: config-file
mountPath: /fluentd/etc/fluent.conf
subPath: fluent.conf
terminationMessagePolicy: File
envFrom:
– configMapRef:
name: caregiver-configmap
image: ‘solucionesregistry.azurecr.io/architecture/fluentd:dev’
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
imagePullSecrets:
– name: solutionsregistry
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600

fluentd-service.yaml

kind: Service
apiVersion: v1
metadata:
name: fluentd
namespace: <NAMESPACE>
labels:
group: onesait-efg
k8s-app: fluentd
run: fluentd
spec:
ports:
– protocol: TCP
port: 24224
targetPort: 24224
selector:
app: fluentd
type: ClusterIP
sessionAffinity: None

fluentd-config-map.yaml

kind: ConfigMap
apiVersion: v1
metadata:
name: fluentd-config-map
namespace: <NAMESPACE>
data:
fluent.conf: |
<source>
@type forward
port 24224
bind 0.0.0.0
</source>
<filter myapp.**>
@type parser
key_name ESTE
reserve_data true
<parse>
@type none
</parse>
</filter>
<match myapp.**>
@type copy
<store>
@type elasticsearch
host elasticdb
port 9200
logstash_format true
logstash_prefix myapp
logstash_dateformat %Y%m%d
include_tag_key true
type_name app_log
tag_key @log_name
flush_interval 1s
user elastic
password changeme
</store>
<store>
@type stdout
</store>
</match>

Configuring the Fluentd config map

In the «fluentd-config-map.yaml» file, there are several places where the text «myapp» appears (lines 13, 21 and 28). This refers to the tag generated in the «logback-spring.xml» file of your microservice inside the «FLUENT_TEXT» appender. This allows you to configure the outputs for different microservices that you need, so that file can be expanded if needed.

Grafana

The Grafana 7.2.2m image, available on DockerHub for download, has been used.

Next, we will detail the necessary files for its configuration in OpenShift:

grafana.yaml

kind: Deployment
apiVersion: apps/v1
metadata:
namespace: onesait-caregiver
labels:
app: grafana
group: onesait-efg
spec:
replicas: 1
selector:
matchLabels:
app: grafana
template:
metadata:
creationTimestamp: null
labels:
app: grafana
spec:
volumes:
– name: config-file
configMap:
name: grafana-config-map
defaultMode: 484
containers:
– resources:
limits:
cpu: 500m
memory: 1Gi
requests:
cpu: 250m
memory: 500Mi
terminationMessagePath: /dev/termination-log
name: grafana
ports:
– name: 3000tcp3000
containerPort: 3000
protocol: TCP
imagePullPolicy: Always
volumeMounts:
– name: config-file
mountPath: /usr/share/grafana/conf/defaults.ini
subPath: defaults.ini
terminationMessagePolicy: File
envFrom:
– configMapRef:
name: caregiver-configmap
image: ‘grafana/grafana:latest’
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
imagePullSecrets:
– name: solutionsregistry
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600

grafana-service.yaml

kind: Service
apiVersion: v1
metadata:
name: grafana
namespace: <NAMESPACE>
labels:
group: onesait-efg
k8s-app: grafana
run: grafana
spec:
ports:
– protocol: TCP
port: 3000
targetPort: 3000
selector:
app: grafana
type: ClusterIP
sessionAffinity: None

grafana-config-map.yaml

As this configuration file is too big, you can download it from the following link.

With this, you have everything configured and ready to work.

Header image: Victoire Joncheray at Unsplash.

Autor

One thought on “Configuration in Kubernetes

Leave a Reply

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