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

时间:2018-06-12 22:02:39

标签: kubernetes minikube kubernetes-helm

我在MacOS上运行minikube,并希望公开用于运行此示例helm图表的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

1 个答案:

答案 0 :(得分:3)

由于minikube来自docker-machine系列,因此运行minikube ip将输出虚拟机的IP地址, 是您应尝试的IP联系您的群集,而不是localhost。

此外,[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公布了此类决定。

另一个&#34;星号&#34; port-forward Service type: NodePort Ingress部分的chart-example.localcurl -H "host: chart-example.local" http://$(minikube ip):${the_ingress_port} Ingress "\\{//([^/]+)/([^/}]+)}" Matcher m = Pattern.compile("\\{//([^/]+)/([^/}]+)}").matcher(str); while (m.find()) { String part1 = m.group(1); String part2 = m.group(2); // do something with the parts } 部分{}} {}} {{}}如果你有一个正在运行的入口控制器,&#34;但是如果你这样做,那么它已经有一个TCP / IP端口,你应该在它上面联系你的集群,只是确保你提供一个m.group()的连接,以便入口控制器可以路由请求到正确的"(?<=\\{)//[^/]+/[^/}]+(?=})"