[Infrastructure as Code (IaC) Pulumi] Use Pulumi kubernetes (K8S) Helm Chart to deploy Elastic Stack (Elasticsearch, APM Server, Kibana, Fluent Bit or Fluentd)
Elastic APM
Elastic Stack includes Elasticsearch, APM Server, Kibana, Fluent Bit or Fluentd etc.
This article is about how to use Pulumi, kubernetes (K8S) provider, Helm Chart and TypeScript SDK to deploy Elastic Stack (Elasticsearch, APM Server, Kibana, Fluent Bit or Fluentd) within Kubernetes (K8S).
-
Elasticsearch is the distributed, RESTful search and analytics engine at the heart of the Elastic Stack. You can use Elasticsearch to store, search, and manage data for Logs, Metrics, A search backend, Application monitoring, Endpoint security and more!
-
Application Performance Monitoring (APM) with Elasticsearch | Elastic - https://www.elastic.co/apm/
Elastic APM is the free and open application performance monitoring. It monitor, detect, and diagnose complex application performance issues to maintain an expected level of service.
-
elastic/kibana: Your window into the Elastic Stack - https://github.com/elastic/kibana
Elastic Kibana is a free and open user interface that lets you visualize your Elasticsearch data and navigate the Elastic Stack. Do anything from tracking query load to understanding the way requests flow through your apps.
-
Fluent Bit or Fluentd
-
(Recommend) Fluent Bit - https://fluentbit.io/
Fluent Bit is an open source Log Processor and Forwarder which allows you to collect any data like metrics and logs from different sources, enrich them with filters and send them to multiple destinations. It’s the preferred choice for containerized environments like Kubernetes.
-
fluent/helm-charts: Helm Charts for Fluentd and Fluent Bit - https://github.com/fluent/helm-charts
Fluentd is an open source data collector for unified logging layer.
-
Prerequisites
-
Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.
See Getting started | Kubernetes - https://kubernetes.io/docs/setup/ to leanr more.
-
Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/
Pulumi is a modern infrastructure-as-code platform that allows you to use common programming languages, tools, and frameworks, to provision, update, and manage cloud infrastructure resources.
Install the Pulumi - https://www.pulumi.com/ CLI.
1
2Mac OS X
brew install pulumiSee Download and Install | Pulumi - https://www.pulumi.com/docs/get-started/install/ to learn more about others OS.
-
Node.js - https://nodejs.org/en/
Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
Install Node.js - https://nodejs.org/en/ CLI.
1
2Mac OS X
brew install nodeSee Node.js - https://nodejs.org/en/ to learn more about others OS.
Usage
Pulumi New
Create the workspace directory.
1 | mkdir -p col-example-pulumi-typescript-elastic-stack |
Pulumi login into local file system.
1 | pulumi login file://. |
Pulumi new a project with kubernetes-typescript SDK.
1 | pulumi new kubernetes-typescript |
The above command will create some files within the current directory.
1 | tree . -L 1 |
Install js-yaml
package to load and parse yaml file.
1 | npm i js-yaml |
Pulumi Configuration
Configure Kubernetes
By default, Pulumi will look for a kubeconfig file in the following locations, just like kubectl:
-
The environment variable:
$KUBECONFIG
, -
Or in current user’s default kubeconfig directory:
~/.kube/config
If the kubeconfig file is not in either of these locations, Pulumi will not find it, and it will fail to authenticate against the cluster. Set one of these locations to a valid kubeconfig file, if you have not done so already.
Elasticsearch
values.yaml
Edit elasticsearch/values.yaml and replace content within {{ }}
.
1 | # values.yaml |
index.ts
1 | // elasticsearch/index.ts |
Elastic APM Server
values.yaml
Edit apm-server/values.yaml and replace content within {{ }}
.
1 | # apm-server/values.yaml |
index.ts
1 | // elasticsearch/index.ts |
Elastic Kibana
Generate a Admin and password Auth.
1 | htpasswd -c ./ing-auth admin |
Remember the base64 output as the next Secret data.
manifests
Edit manifests/kibana/Secret.yaml and replace content within {{ }}
.
1 | # manifests/kibana/Secret.yaml |
values.yaml
Edit values.yaml and replace content within {{ }}
.
1 | # kibana/values.yaml |
index.ts
Edit ./kibana/index.ts
1 | // kibana/index.ts |
Fluent Bit
values.yaml
Edit fluent-bit/values.yaml and replace content within {{ }}
.
1 | # fluent-bit/values.yaml |
index.ts
Edit ./kibana/index.ts
1 | // kibana/index.ts |
Elastic Stack
main.ts
Edit ./main.ts
1 | // main.ts |
Check all files.
1 | tree . -L 1 |
Pulumi Up
Run pulumi up to create the namespace and pods.
1 | pulumi up |
See pods about apm-server.
1 | kubectl get pods -n elastic |
Pulumi Destroy
Destroy all resources created by Pulumi.
1 | pulumi destroy |
References
[2] Application Performance Monitoring (APM) with Elasticsearch | Elastic - https://www.elastic.co/apm/
[3] elastic/kibana: Your window into the Elastic Stack - https://github.com/elastic/kibana
[4] Fluent Bit - https://fluentbit.io/
[5] fluent/helm-charts: Helm Charts for Fluentd and Fluent Bit - https://github.com/fluent/helm-charts
[7] Kubernetes Getting Started | Pulumi - https://www.pulumi.com/docs/get-started/kubernetes/
[8] Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/
[9] Kubernetes - https://kubernetes.io/
[10] TypeScript: Typed JavaScript at Any Scale. - https://www.typescriptlang.org/