I use this yml file to deploy elasticsearch on kubernetes:
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
labels:
app: elasticsearch
spec:
selector:
matchLabels:
app: elasticsearch
replicas: 1
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
image: elasticsearch:5.6.16
resources:
requests:
memory: 2Gi
limits:
memory: 4Gi
ports:
- containerPort: 9200
- containerPort: 9300
env:
- name: discovery.type
value: single-node
- name: cluster.name
value: elasticsearch
- name: node.name
value: node-1
How I can set permanent internal url which can be used to access the elasticsearch pod from another pod. I can make this successfully this request on port 9200:
curl -X GET 10.233.75.8:9200
{
"name" : "uzspw5E",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "IB59izzDRTypCaZ3Nhbcgw",
"version" : {
"number" : "5.6.16",
"build_hash" : "3a740d1",
"build_date" : "2019-03-13T15:33:36.565Z",
"build_snapshot" : false,
"lucene_version" : "6.6.1"
},
"tagline" : "You Know, for Search"
}
But port 9300 is not working:
curl -X GET 10.233.75.8:9300
curl: (7) Failed to connect to 10.233.75.8 port 9300: Connection refused
Do you know how I can open this port?
If you need to access the Elasticsearch service from another pod, consider creating a Kubernetes Service object that targets your Elasticsearch Deployment. This will provide a stable endpoint (the Service’s ClusterIP) that other pods can use to access the Elasticsearch API on port 9200.
Here’s an example of how you might define such a Service:
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
labels:
app: elasticsearch
spec:
selector:
app: elasticsearch
ports:
- protocol: TCP
port: 9200
targetPort: 9200
With this Service in place, other pods should be able to access the Elasticsearch API via http://elasticsearch:9200.