首页 > 解决方案 > 在 Kubernetes 上部署和公开应用程序

问题描述

在 Ubuntu 上,我使用 minikube 在 kubernetes 上部署和公开应用程序。我遇到了如何使用和查看应用程序的问题。

我使用此链接来解决此问题。

minikube service --url $SERVICE

我希望输出显示我在 kubernetes 上部署的应用程序。

当我点击 ubuntu 终端中的链接时,谷歌浏览器的实际输出是:

This site can’t be reached 
192.168.99.108 refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED

这是 pod 定义:

priority: 0
  restartPolicy: Always
  schedulerName: default-scheduler
  securityContext: {}
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: default-token-6sw9l
    secret:
      defaultMode: 420
      secretName: default-token-6sw9l
status:
  conditions:
  - lastProbeTime: null
    lastTransitionTime: "2019-09-21T22:50:02Z"
    status: "True"
    type: Initialized
  - lastProbeTime: null
    lastTransitionTime: "2019-09-23T22:05:36Z"
    status: "True"
    type: Ready
  - lastProbeTime: null
    lastTransitionTime: "2019-09-23T22:05:36Z"
    status: "True"
    type: ContainersReady
  - lastProbeTime: null
    lastTransitionTime: "2019-09-21T22:50:02Z"
    status: "True"
    type: PodScheduled
  containerStatuses:
  - containerID: 
docker://57c0d2fccc9698ace22600f3d3197416324ed3bf570f929562d4669bd018d77f
    image: .../test:latest
    imageID: docker-pullable://.../test@sha256:fc6e42ba94b04cafa64c77b76961243695e03441ce0a54d21f22db99c8fdf7d7
        lastState:
          terminated:
            containerID: docker://e5ed21b41e7075681d6be8b46954e8bb5b2e6be2ef63942951b41176d583f03e
            exitCode: 0
            finishedAt: "2019-09-23T21:44:21Z"
            reason: Completed
            startedAt: "2019-09-23T21:43:40Z"
        name: test
        ready: true
        restartCount: 3
        state:
          running:
            startedAt: "2019-09-23T22:05:28Z"
      hostIP: 10.0.2.15
      phase: Running
      podIP: 172.17.0.9
      qosClass: BestEffort
      startTime: "2019-09-21T22:50:02Z"

这是服务定义:

apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2019-09-21T22:50:13Z"
  labels:
    app: tesb-node
  name: tesb-node
  namespace: default
  resourceVersion: "51502"
  selfLink: /api/v1/namespaces/default/services/tesb-node
  uid: d0182ca7-cbd0-4c56-a2b7-a9e6f1c64621
spec:
  clusterIP: 10.99.98.201
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 30178
    port: 84
    protocol: TCP
    targetPort: 84
  selector:
    app: tesb-node
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer: {}

标签: kuberneteskubernetes-pod

解决方案


您需要使用 ip 传递 NodePort 编号才能接收响应。可以试试

kubectl get service $SERVICE --output='jsonpath="{.spec.ports[0].nodePort}"'

获取端口号?


推荐阅读