Setting up ELK stack on Kubernetes in docker for windows.
First of all, I’m installing Helm from the releases page, the windows version. I copied to the typical windows program files folder and updated the PATH environment variable to check the new helm folder. So now I can use it in console. I studied the following tutorials: - https://blog.knoldus.com/how-to-deploy-elk-stack-on-kubernetes/ - https://tharangarajapaksha.medium.com/elk-stack-in-k8s-cluster-13bb509185e0 - https://www.cloudsigma.com/installing-software-on-kubernetes-with-helm-3-package-manager-on-windows/
I’m going to create a new namespace in the k8s cluster for elk stack.
kubectl create namespace elk
Because I have Helm, I’m going to install the ingress controller using the following command:
--install ingress-nginx ingress-nginx --repo https://kubernetes.github.io/ingress-nginx --namespace ingress-nginx --create-namespace helm upgrade
Now I’m going to install the helm chart for elasticsearch, I’m using the default values, but I’m going to change the name of the release to elk.
I’m using the guide from elastic.co here
-f https://download.elastic.co/downloads/eck/2.8.0/crds.yaml kubectl create
Now, I’m going to install the operator, which is the one that will create the elasticsearch cluster.
-f https://download.elastic.co/downloads/eck/2.8.0/operator.yaml kubectl apply
Monitor the operator deployment until it is ready:
-n elastic-system logs -f statefulset.apps/elastic-operator kubectl
Now, I’m going to apply the operator configuration, which is the one that will create the elasticsearch cluster.
Create a file with the following content:
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
spec:
version: 8.8.2
nodeSets:
- name: default
count: 1
config:
node.store.allow_mmap: false
and now apply it:
-f elasticsearch.yaml kubectl apply
It will take a while to be available, you can check the status with the following command:
kubectl get elasticsearch
and the output:
NAME HEALTH NODES VERSION PHASE AGE.8.2 ApplyingChanges 46s quickstart unknown 8
when it’s ready, the output will be:
NAME HEALTH NODES VERSION PHASE AGE.8.2 Ready 2m38s quickstart green 1 8
You can check the pods with the following command:
--selector='elasticsearch.k8s.elastic.co/cluster-name=quickstart' kubectl get pods
Request Elasticsearch access
first, check the cluster IP:
-es-http kubectl get service quickstart
Next, get the credentials (you can use powershell)
$PASSWORD = kubectl get secret quickstart-es-elastic-user -o go-template='{{.data.elastic | base64decode}}'
or you can use cmd:
curl -u "elastic:$PASSWORD" -k "https://localhost:9200"
{
"name" : "quickstart-es-default-0",
"cluster_name" : "quickstart",
"cluster_uuid" : "WWtwSzimREaMT38n65lghA",
"version" : {
"number" : "8.8.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "98e1271edf932a480e4262a471281f1ee295ce6b",
"build_date" : "2023-06-26T05:16:16.196344851Z",
"build_snapshot" : false,
"lucene_version" : "9.6.0",
"minimum_wire_compatibility_version" : "7.17.0",
"minimum_index_compatibility_version" : "7.0.0"
},
"tagline" : "You Know, for Search"
}
Kibana
To deploy Kibana, we use the following file:
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: quickstart
spec:
version: 8.8.2
count: 1
elasticsearchRef:
name: quickstart
The command to apply it is:
-f .\kibana.yaml kubectl apply
Check the status and wait until it’s ready:
kubectl get kibana
The output will be:
NAME HEALTH NODES VERSION AGE.8.2 38s quickstart red 8
When it’s ready, the output will be:
.8.2 4m9s quickstart green 1 8
Check the pods:
--selector='kibana.k8s.elastic.co/name=quickstart' kubectl get pod
The output will be:
NAME READY STATUS RESTARTS AGE-kb-66fb9f8b65-bsdp7 1/1 Running 0 5m20s quickstart
Now, check the service:
-kb-http kubectl get service quickstart
The output will be:
TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
NAME -kb-http ClusterIP 10.111.153.143 <none> 5601/TCP 5m40s quickstart
You can now forward the port
-forward service/quickstart-kb-http 5601 kubectl port
Get the password:
-es-elastic-user -o=jsonpath='{.data.elastic}' | %{[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_))}; kubectl get secret quickstart
It’s the same as the elasticsearch password. Anyway, let’s connect to the web interface, open a browser and go to https://localhost:5601