无法从外部IP Azure devops kubernetes访问服务

时间:2019-07-16 06:28:07

标签: kubernetes azure-devops

我可以通过运行获取服务

$ kubectl get service <service-name> --namespace <namespace name>

NAME          TYPE           CLUSTER-IP  EXTERNAL-IP  PORT(S)       AGE
service name  LoadBalancer   *********   *********    port numbers  16h

这是我在Kubernetes上运行的服务,但是我无法通过公共IP访问它。以下是我添加的服务和部署文件。我正在使用azre devops构建容器映像并将其释放到azure容器注册表。正如您在服务描述中看到的那样,我获得了外部IP和群集IP,但是当我在浏览器中尝试使用此IP或使用curl时,我没有任何响应。 `

{
  "kind": "Service",
  "apiVersion": "v1",
  "metadata": {
    "name": "service-name",
    "namespace": "namespace-name",
    "selfLink": "*******************",
    "uid": "*******************",
    "resourceVersion": "1686278",
    "creationTimestamp": "2019-07-15T14:12:11Z",
    "labels": {
      "run": "service name"
    }
  },
  "spec": {
    "ports": [
      {
        "protocol": "TCP",
        "port": 80,
        "targetPort": ****,
        "nodePort": ****
      }
    ],
    "selector": {
      "run": "profile-management-service"
    },
    "clusterIP": "**********",
    "type": "LoadBalancer",
    "sessionAffinity": "None",
    "externalTrafficPolicy": "Cluster"
  },
  "status": {
    "loadBalancer": {
      "ingress": [
        {
          "ip": "*************"
        }
      ]
    }
  }
}
{
  "kind": "Deployment",
  "apiVersion": "extensions/v1beta1",
  "metadata": {
    "name": "deployment-name",
    "namespace": "namespace-name",
    "selfLink": "*************************",
    "uid": "****************************",
    "resourceVersion": "1686172",
    "generation": 1,
    "creationTimestamp": "2019-07-15T14:12:04Z",
    "labels": {
      "run": "deployment-name"
    },
    "annotations": {
      "deployment.kubernetes.io/revision": "1"
    }
  },
  "spec": {
    "replicas": 1,
    "selector": {
      "matchLabels": {
        "run": "deployment-name"
      }
    },
    "template": {
      "metadata": {
        "creationTimestamp": null,
        "labels": {
          "run": "deployment-name"
        }
      },
      "spec": {
        "containers": [
          {
            "name": "deployment-name",
            "image": "dev/containername:50",
            "ports": [
              {
                "containerPort": ****,
                "protocol": "TCP"
              }
            ],
            "resources": {},
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "IfNotPresent"
          }
        ],
        "restartPolicy": "Always",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {},
        "schedulerName": "default-scheduler"
      }
    },
    "strategy": {
      "type": "RollingUpdate",
      "rollingUpdate": {
        "maxUnavailable": 1,
        "maxSurge": 1
      }
    },
    "revisionHistoryLimit": 2147483647,
    "progressDeadlineSeconds": 2147483647
  },
  "status": {
    "observedGeneration": 1,
    "replicas": 1,
    "updatedReplicas": 1,
    "readyReplicas": 1,
    "availableReplicas": 1,
    "conditions": [
      {
        "type": "Available",
        "status": "True",
        "lastUpdateTime": "2019-07-15T14:12:04Z",
        "lastTransitionTime": "2019-07-15T14:12:04Z",
        "reason": "MinimumReplicasAvailable",
        "message": "Deployment has minimum availability."
      }
    ]
  }
}

`

2 个答案:

答案 0 :(得分:1)

显然标签和选择器不匹配:

服务选择器

"selector": {
      "run": "profile-management-service"

带有部署标签

"labels": {
      "run": "deployment-name"
    },

还要检查服务的 targetPort 值,它应与部署的 containerPort 相匹配

答案 1 :(得分:0)

您需要在部署中添加readinessProbelivenessProbe,然后检查防火墙是否所有规则正确。

Here,您会获得更多有关活力和准备状态的信息