Kubernetes - Service configuration runs but not exposed

1/13/2022

I have an opensearch app which I want to expose via a service so it can communicate with the opensearch-dashboard app I got. when I open a shell in the pod I see that the opensearch server works properly.

when I run to extract the url :

cat /etc/hosts

I get:

opensearch-master-headless-0.opensearch-master-headless.search.svc.cluster.local

if I run this in the same pod, I get 200 response.:

curl -XGET http://opensearch-master-headless-0.opensearch-master-headless.search.svc.cluster.local:9200 -u 'admin:admin' --insecure

if I run it from the dashboard pod in the same namespace it says its not resolved:

curl -XGET http://opensearch-master-headless-0.opensearch-master-headless.search.svc.cluster.local:9200 -u 'admin:admin' --insecure

my service.yml

---
kind: Service
apiVersion: v1
metadata:
  name: {{ .Values.global.appName }} --- evaluates to opensearch
  namespace: {{ .Values.global.namespace }} --- evaluates to search
spec:
  type: ClusterIP
  clusterIP: None
  publishNotReadyAddresses: true
  ports:
    - name: "http"
      protocol: TCP
      port: 9200
    - name: "transport"
      protocol: TCP
      port: 9300
---

But, If I use the opensearch's pod IP Address:

curl -XGET http://<IP-ADDRESS>:9200 -u 'admin:admin' --inse

cure

this works from the opensearch pod

  • I'm using argocd to deploy, when I deploy the opensearch app, it doesnt raises any errors on my service configuration
-- yovel cohen
helmfile
kubernetes
kubernetes-helm
opensearch-dashboards

1 Answer

1/13/2022

You can access via type NodePort of Service

---
kind: Service
apiVersion: v1
metadata:
  name: {{ .Values.global.appName }} --- evaluates to opensearch
  namespace: {{ .Values.global.namespace }} --- evaluates to search
spec:
  type: NodePort
  clusterIP: None
  publishNotReadyAddresses: true
  ports:
    - name: "http"
      protocol: TCP
      port: 9200
      nodePort: 30920
    - name: "transport"
      protocol: TCP
      port: 9300
      nodePort: 30930
---

Then, call via IP of Node k8s
(get IP of Node k8s by command kubectl get node -o wide - at field INTERNAL-IP)

curl -XGET http://<INTERNAL-IP>:30920 -u 'admin:admin' --insecure

-- quoc9x
Source: StackOverflow