kubernetes - helm chart 不会将 ip 地址暴露给 ping localhost :port

标签 kubernetes minikube kubernetes-helm

我在 MacOS 上运行 minikube,并希望公开运行此示例 Helm chart 的 IP 地址和端口 -
https://docs.bitnami.com/kubernetes/how-to/create-your-first-helm-chart/

我试图 ping localhost:58064,但它无法连接。

helm install --dry-run --debug ./mychart --set service.internalPort=8080
[debug] Created tunnel using local port: '58064'

[debug] SERVER: "127.0.0.1:58064"

[debug] Original chart version: ""
[debug] CHART PATH: /Users/me/Desktop/HelmTest/mychart

NAME:   messy-penguin
REVISION: 1
RELEASED: Tue Jun 12 17:56:41 2018
CHART: mychart-0.1.0
USER-SUPPLIED VALUES:
service:
  internalPort: 8080

COMPUTED VALUES:
affinity: {}
image:
  pullPolicy: IfNotPresent
  repository: nginx
  tag: stable
ingress:
  annotations: {}
  enabled: false
  hosts:
  - chart-example.local
  path: /
  tls: []
nodeSelector: {}
replicaCount: 1
resources: {}
service:
  internalPort: 8080
  port: 80
  type: ClusterIP
tolerations: []

HOOKS:
MANIFEST:

---
# Source: mychart/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: messy-penguin-mychart
  labels:
    app: mychart
    chart: mychart-0.1.0
    release: messy-penguin
    heritage: Tiller
spec:
  type: ClusterIP
  ports:
    - port: 80
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app: mychart
    release: messy-penguin
---
# Source: mychart/templates/deployment.yaml
apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: messy-penguin-mychart
  labels:
    app: mychart
    chart: mychart-0.1.0
    release: messy-penguin
    heritage: Tiller
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mychart
      release: messy-penguin
  template:
    metadata:
      labels:
        app: mychart
        release: messy-penguin
    spec:
      containers:
        - name: mychart
          image: "nginx:stable"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {}
MacBook-Pro:~/Desktop/HelmTest quantum-fusion$ curl 127.0.0.1:58064
curl: (7) Failed to connect to 127.0.0.1 port 58064: Connection refused

最佳答案

因为 minikube 来自 docker-machine 系列,运行 minikube ip 将输出虚拟机的 IP 地址,而 表示 是您应该尝试联系集群的 IP,而不是本地主机。

此外,[debug] Created tunnel using local port: '58064' helm 建立一个隧道到集群内的嵌入式 tiller Pod,并且根本不是你应该使用的任何东西。这就是为什么它以 [debug] 为前缀的原因:因为它只在极端情况下有用。

最后,您需要使用 kubectl port-forward 来访问您部署的 Pod,因为 Service 使用的是 ClusterIP ,顾名思义,它仅在集群内部有效。您还可以创建 Service 的第二个 type: NodePort ,它将在虚拟机的 IP 上分配一个 TCP/IP 端口,该端口路由到 port:Service 。您可以通知您的 Helm 图表为您执行此操作,具体取决于作者是否通过图表的 values.yaml 公开了这种决定。
port-forwardService 部分的 type: NodePort 的另一个“星号”是,我在输出中看到了 Ingresschart-example.local 资源的提及,但该 Controller 在实际运行时才有意义,但只有在您运行时才有意义那么它已经有一个 TCP/IP 端口,您应该通过该端口联系您的集群,只需确保您提供带有 curl -H "host: chart-example.local" http://$(minikube ip):${the_ingress_port} 的连接,以便入口 Controller 可以将请求路由到正确的 Ingress

关于kubernetes - helm chart 不会将 ip 地址暴露给 ping localhost :port,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50826457/

相关文章:

kubernetes - 在Google Cloud Kubernetes中运行Traefik时,LoadBalancer Healthy失败

kubernetes - Kubectl 和 Minikube 问题 - 无法连接到服务器

kubernetes - helm 和 kubectl 上下文不匹配

kubernetes - 为多个不同的kubernetes服务重用相同的镜像,配置和 secret

kubernetes - 为什么内存使用量比我在 Kubernetes 的节点中设置的要大?

spring - 在集群外访问 Kubernetes Configmap

kubernetes - 我可以远程托管minikube以便在团队中进行开发吗?

docker - 无法连接到主机中的minikube服务

docker - 在没有注册的情况下使用 Minikube 使用 Skaffold

python - 在 Kubernetes 中运行 Apache Beam python 管道