In a post 2 years ago, I've specified steps to deploy ElasticSearch and TLS on kubernetes. It was back then, when ElasticSearch and kubernetes have only started dating, and the integration was not simple. But now ElasticSearch deployment is built-in part of the product, and much simpler.
This post is based mostly on the Elastic Cloud documentation.
CRDs
Like most of the operator based deployments, CRDs are required:
kubectl create -f https://download.elastic.co/downloads/eck/2.6.1/crds.yaml
Operator
kubectl apply -f https://download.elastic.co/downloads/eck/2.6.1/operator.yaml
Kind and Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: elastic-ingress-kind
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- host: elastic
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: elastic-es-http
port:
number: 9200
- host: kibana
http:
paths:
- pathType: ImplementationSpecific
backend:
service:
name: kibana-kb-http
port:
number: 5601
Elastic
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: elastic
spec:
http:
tls:
selfSignedCertificate:
disabled: true
version: 8.6.0
nodeSets:
- name: default
count: 1
config:
node.store.allow_mmap: false
Password=$(kubectl get secret elastic-es-elastic-user -o go-template='{{.data.elastic | base64decode}}')
echo "Password is ${Password}"
curl -k -u "elastic:${Password}" "http://elastic"
kubectl get elasticsearch
#!/bin/bash
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
function isReady(){
kubectl get elasticsearch
kubectl get pods
count=$(kubectl get elasticsearch | grep green | wc -l)
if [[ "${count}" == "0" ]]; then
return 1
else
return 0
fi
}
function waitForReady(){
until isReady
do
echo "waiting for elastic to be green"
sleep 5
done
echo "elastic is ready"
}
function sendRequest(){
Password=$(kubectl get secret elastic-es-elastic-user -o go-template='{{.data.elastic | base64decode}}')
echo "Password is ${Password}"
set -x
curl -k -u "elastic:${Password}" "http://elastic"
}
waitForReady
sendRequest
Kibana
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: kibana
spec:
http:
tls:
selfSignedCertificate:
disabled: true
version: 8.6.0
count: 1
elasticsearchRef:
name: elastic
#!/bin/bash
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
function isReady(){
kubectl get kibana
kubectl get pods
count=$(kubectl get kibana | grep green | wc -l)
if [[ "${count}" == "0" ]]; then
return 1
else
return 0
fi
}
function waitForReady(){
until isReady
do
echo "waiting for kibana to be green"
sleep 5
done
echo "kibana is ready"
}
waitForReady
Cleanup
kubectl delete kibana --all
kubectl delete elastic --all
kubectl delete -f ingress.yaml