无法连接到外部IP上的Kubernetes集群

时间:2018-08-27 19:14:49

标签: azure kubernetes

我正在尝试访问.NET Web API,该Web服务是我在docker上实现的,并安装在Microsoft Azure的Kubernet群集中。

该应用程序在本地docker机器上运行良好。 集群正在运行,我的部署是正确的,并且已在Pod中创建了集群。我检查的所有内容都很好,但是我无法通过外部群集IP(负载平衡器)访问我的应用程序。这是我的YAML部署文件:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ohmioapi-deployment
spec:
  selector:
    matchLabels:
      app: ohmioapi
  replicas: 1
  template:
    metadata:
      labels:
        app: ohmioapi
    spec:
      containers:
      - name: ohmioapi
        image: ohmiocontainers.azurecr.io/ohmioapi:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 15200
      imagePullSecrets:
        - name: acr-auth
---
apiVersion: v1
kind: Service
metadata:
  name: ohmioapi
  labels:
    app: ohmioapi
spec:
  selector:
    app: ohmioapi
  ports:
  - port: 15200
    nodePort: 30200
    protocol: TCP
  type: LoadBalancer

任何人都可以提示从哪里开始寻找? 谢谢!

3 个答案:

答案 0 :(得分:1)

我会给部署/吊舱端口起一个名字(例如http),然后使服务从80端口开始服务,但要按名称定位吊舱端口...那样,您不必担心连接到服务时的端口号。

此外,如果您使用的是nodePort类型,则不需要或不想使用LoadBalancer

例如

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ohmioapi-deployment
spec:
  selector:
    matchLabels:
      app: ohmioapi
  replicas: 1
  template:
    metadata:
      labels:
        app: ohmioapi
    spec:
      containers:
      - name: ohmioapi
        image: ohmiocontainers.azurecr.io/ohmioapi:latest
        imagePullPolicy: Always
        ports:
        - name: http
          containerPort: 15200
      imagePullSecrets:
        - name: acr-auth

---
apiVersion: v1
kind: Service
metadata:
  name: ohmioapi
  labels:
    app: ohmioapi
spec:
  selector:
    app: ohmioapi
  ports:
  - name: http
    port: 80
    targetPort: http
    protocol: TCP
  type: LoadBalancer

答案 1 :(得分:1)

您可以使用命令kubectl get service获取服务的所有信息并检查服务ohmioapi,结果如下:

enter image description here

或者您可以使用命令kubectl describe service serviceName获取有关服务的更多详细信息,结果将如下所示:

enter image description here

您可以在负载均衡器中检查端口映射,并可以通过外部IP和端口从浏览器进行访问。

您还可以使用命令kubectl edit service serviceName编辑和检查Kunernetes创建的配置文件,结果将如下所示:

enter image description here

答案 2 :(得分:0)

确定要使用“ targetport”而不是“ nodeport”(如果端口相同,则只需将其删除)。

https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer

相关问题