【问题标题】:Kubernetes - Service configuration runs but not exposedKubernetes - 服务配置运行但未公开
【发布时间】:2022-01-13 16:22:46
【问题描述】:

我有一个 opensearch 应用程序,我想通过服务公开它,以便它可以与我得到的 opensearch-dashboard 应用程序通信。 当我在 pod 中打开 shell 时,我看到 opensearch 服务器工作正常。

当我运行提取网址时:

cat /etc/hosts

我明白了:

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

如果我在同一个 pod 中运行它,我会得到 200 响应。:

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

如果我从同一命名空间中的仪表板 pod 运行它,它会说它没有解决:

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

我的服务.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
---

但是,如果我使用 opensearch 的 pod IP 地址:

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

cure

这适用于 opensearch pod

  • 我正在使用 argocd 进行部署,当我部署 opensearch 应用程序时,它不会在我的服务配置上引发任何错误

【问题讨论】:

  • 您应该能够使用服务的名称和命名空间,如 Kubernetes 文档中DNS for Services and Pods 中所述; http://opensearch.search.svc.cluster.local:9200.
  • @DavidMaze 的建议对您有帮助吗?

标签: kubernetes kubernetes-helm helmfile opensearch-dashboards


【解决方案1】:

您可以通过输入NodePortService 访问

---
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
---

然后,通过Node k8s的IP调用
(通过命令kubectl get node -o wide获取Node k8s的IP-INTERNAL-IP字段)

curl -XGET http://&lt;INTERNAL-IP&gt;:30920 -u 'admin:admin' --insecure

【讨论】:

  • 谢谢,但我的问题是我不想使用对我有用的 IP。我想使用 DNS 名称,这样它就会在部署过程中持续存在。
  • 所以,你可以在 k8s 中使用 ingress 来做到这一点。
猜你喜欢
  • 2019-01-10
  • 2020-04-07
  • 2019-04-29
  • 2019-01-05
  • 2021-02-22
  • 2021-12-15
  • 2021-12-21
  • 2019-09-26
  • 2019-01-04
相关资源
最近更新 更多