在kubernetes上部署和公开应用程序

在kubernetes上部署和公开应用程序,kubernetes,kubernetes-pod,Kubernetes,Kubernetes Pod,在Ubuntu上,我使用minikube在kubernetes上部署和公开应用程序。我遇到了如何使用和查看应用程序的问题 我用这个来解决这个问题 minikube服务--url$service 我希望输出显示我在kubernetes上部署的应用程序 当我点击ubuntu终端中的链接时,google chrome的实际输出是: This site can’t be reached 192.168.99.108 refused to connect. Try: Checking the conne

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

我用这个来解决这个问题

minikube服务--url$service

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

当我点击ubuntu终端中的链接时,google chrome的实际输出是:

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: {}
以下是服务定义:

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: {}

您需要通过ip传递节点端口号才能接收响应。我可以试一试吗

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

要获取端口号?

您需要将节点端口号与ip一起传递才能接收响应。我可以试一试吗

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

要获取端口号?

正如我们在pod定义中看到的,您的pod中没有containerPort,添加它,一切都应该正常

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80

正如我们在您的pod定义中看到的,您的pod中没有containerPort,添加它,一切都应该正常工作

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-nginx
spec:
  selector:
    matchLabels:
      run: my-nginx
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        image: nginx
        ports:
        - containerPort: 80


您是否正在寻找此命令
minikube dashboard
以在web浏览器中访问k8 dashboard?您要部署和公开哪个应用程序?你能添加yaml文件吗?我想部署和公开的应用程序有vs代码(asp.net核心),你能告诉我minikube是否在你的本地电脑上工作吗?或者就像你在一台pc/笔记本电脑上工作,你有一个带有ubuntu的虚拟机?@Martijn数据已经附加在上面了,所以我已经删除了重复的附加数据。你在寻找这个命令
minikube dashboard
来访问web浏览器中的k8 dashboard吗?你想部署和公开什么应用程序?你能添加yaml文件吗?我想部署和公开的应用程序有vs代码(asp.net核心),你能告诉我minikube是否在你的本地电脑上工作吗?或者就像你在一台pc/笔记本电脑上工作,你有一个带有ubuntu的虚拟机?@Martijn数据已经附加在上面了,所以我删除了重复的附加数据,我得到了端口号。我使用了群集ip的端口号,输出是:无法访问此站点。。。反应时间太长了。尝试:检查连接检查代理和防火墙错误连接超时(在这种情况下我还能做什么?)kubectl get svc的输出是节点端口。我在google chrome中使用了集群ip(http://),结果是:无法访问此站点10.111.127.243响应时间过长。尝试:检查连接检查代理和防火墙错误连接超时顺便说一句,当我部署这个应用并向kubernetes公开它时,我忘了提到它有asp.net核心。如何解决此问题?您的播客是否已启动并运行?此应用程序的service?Pod中的端口已启动并正在运行。虽然节点端口未设置,但目标端口已设置。我已获得端口号。我使用了群集ip的端口号,输出是:无法访问此站点。。。反应时间太长了。尝试:检查连接检查代理和防火墙错误连接超时(在这种情况下我还能做什么?)kubectl get svc的输出是节点端口。我在google chrome中使用了集群ip(http://),结果是:无法访问此站点10.111.127.243响应时间过长。尝试:检查连接检查代理和防火墙错误连接超时顺便说一句,当我部署这个应用并向kubernetes公开它时,我忘了提到它有asp.net核心。如何解决此问题?您的播客是否已启动并运行?此应用程序的service?Pod中的端口已启动并正在运行。虽然节点端口未设置,但目标端口已设置。如何获取containerPort?我应该把containerPort放在哪里来实现这一点?您只需要将其写入部署yaml文件。将
端口:-containerPort:84
添加到spec.containers。部署中的containerPort必须与服务中的targetPort相同,因此在您的示例中为84。如何获取containerPort?我应该把containerPort放在哪里来实现这一点?您只需要将其写入部署yaml文件。将
端口:-containerPort:84
添加到spec.containers。部署中的containerPort必须与服务中的targetPort相同,因此在您的示例中为84。