【问题标题】:kubernetes service return refusedKubernetes 服务返回被拒绝
【发布时间】:2017-06-01 08:43:53
【问题描述】:

我要发疯了。我尝试在 Google Cloud 上的 kubernetes 中公开我的服务。我的 pod 已启动,没有错误,我的服务已创建。但是当我继续或卷曲时,我得到:

无法连接到 130。..*** 端口 80:连接被拒绝

apiVersion: v1
kind: Service
metadata:
  name: k8s-symfony-nginx
  labels:
    name: k8s-symfony-nginx
spec:
  type: LoadBalancer #expose
  ports:
  - port: 80
  selector:
    type: my-app

和复制:

apiVersion: v1
kind: ReplicationController
metadata:
  name: k8s-symfony-nginx
  labels:
    name: k8s-symfony-nginx
spec:
  replicas: 1
  selector:
    name: k8s-symfony-nginx
    type: my-app
  template:
    metadata:
      labels:
        name: k8s-symfony-nginx
        type: my-app
    spec:
      containers:
        - name: nginx
          image: phpdockerio/nginx:latest
          ports:
            - name: web
              containerPort: 80
        - name: php
          image: gcr.io/myproject-138623/newcom4u/k8s-symfony-php:latest
          ports:
            - name: php
              containerPort: 9000

kubectl get svc 的输出是:

k8s-symfony-nginx 10.3.. 104.199.. 80:30274/TCP
4m

kubectl describe 在我的服务上的输出是:

Name:           k8s-symfony-nginx
Namespace:      default
Labels:         name=k8s-symfony-nginx
Selector:       name=k8s-symfony-nginx,type=my-app
Type:           LoadBalancer
IP:         10.******
LoadBalancer Ingress:   104.*****
Port:           <unset> 80/TCP
NodePort:       <unset> 30274/TCP
Endpoints:      10.0.0.9:80
Session Affinity:   None
Events:
  FirstSeen LastSeen    Count   From            SubObjectPath   Type        Reason          Message
  --------- --------    -----   ----            -------------   --------    ------          -------
  12m       12m     1   {service-controller }           Normal      CreatingLoadBalancer    Creating load balancer
  11m       11m     1   {service-controller }           Normal      CreatedLoadBalancer Created load balancer

【问题讨论】:

  • kubectl get svc 的输出是什么?
  • k8s-symfony-nginx 10.3.***.*** 104.199.***.*** 80:30274/TCP 4m
  • 您能否检查 kubectl describe 输出,看看它是否确实以您期望的方式绑定?这似乎是配置错误或防火墙规则。
  • 查看我的编辑,问题与“端口: 80/TCP”有关?
  • &lt;unset&gt; 不应该是问题 - 您是否仔细检查了 pod 是否实际运行没有错误?例如。与:kubectl logs $(kubectl get pods -l name=k8s-symfony-nginx -o name)

标签: kubernetes google-cloud-platform


【解决方案1】:

我有同样的问题,我改变了

apiVersion: v1
kind: Service
metadata:
  name: k8s-symfony-nginx
  labels:
  name: k8s-symfony-nginx
spec:
type: LoadBalancer #expose
  ports:
  - port: 80
  selector:
    type: my-app

apiVersion: v1
kind: Service
metadata:
  name: k8s-symfony-nginx
  labels:
  name: k8s-symfony-nginx
spec:
type: LoadBalancer #expose
  ports:
  - port: 80
  selector:
    app: my-app

type 应该在 selector 中改为 app

【讨论】:

  • 您能解释一下为什么将标签选择器更改为 app: my-app 有效吗?
  • @Malathi 我将我的代码与一些文档进行了比较,发现了这种差异......然后试了一下。幸运的是它对我有用。我不知道为什么,因为我不再使用 Kubernetes 了……所以我没有深入挖掘……
猜你喜欢
  • 1970-01-01
  • 2019-06-01
  • 2020-05-03
  • 2021-09-13
  • 2016-05-02
  • 2021-05-25
  • 2020-11-08
  • 1970-01-01
  • 2021-01-20
相关资源
最近更新 更多