无法访问在Azure ACS Kubernetes群集中部署的Web API

时间:2018-07-26 14:57:47

标签: azure kubernetes docker-compose asp.net-core-webapi

请帮助。我正在尝试将Web API部署到Azure ACS Kubernetes群集,这是在VSTS中创建的简单Web API,其结果应为: { "value1", "value2" }

我打算将该类型设置为Cluster-IP,但是我想先测试并访问它,这就是LoadBalancer的原因,吊舱正在运行并且没有重新启动(我认为很好)。

我要遵循的指南是:Running Web API using Docker and Kubernetes

NAME                TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)            AGE
kubernetes          ClusterIP      10.0.0.1       <none>         443/TCP            3d
sampleapi-service   LoadBalancer   10.0.238.155   102.51.223.6      80:31676/TCP   1h

当我尝试浏览IP 102.51.223.6/api/values时说:

  

“无法访问此网站”

service.yaml

kind: Service
apiVersion: v1
metadata:
  name: sampleapi-service
  labels:
    name: sampleapi
    app: sampleapi
spec:
  selector:
    name: sampleapi
  ports:
   - protocol: "TCP"
     # Port accessible inside the cluster
     port: 80
     # Port to forwards inside the pod
     targetPort: 80
     # Port accessible oustide the cluster
     #nodePort: 80
  type: LoadBalancer

deployment.yml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: sampleapi-deployment
spec:
  replicas: 3
  template:
    metadata:
      labels:
        app: sampleapi
    spec:
      containers:
      - name: sampleapi
        image: mycontainerregistry.azurecr.io/sampleapi:latest
        ports:
        - containerPort: 80

POD

Name:           sampleapi-deployment-498305766-zzs2z
Namespace:      default
Node:           c103facs9001/10.240.0.4
Start Time:     Fri, 27 Jul 2018 00:20:06 +0000
Labels:         app=sampleapi
                pod-template-hash=498305766
Annotations:    kubernetes.io/created-by={"kind":"SerializedReference","apiVersion":"v1","reference":{"kind":"ReplicaSet","namespace":"default","name":"sampleapi-deployme
-498305766","uid":"d064a8e0-9132-11e8-b58d-0...
Status:         Running
IP:             10.244.2.223
Controlled By:  ReplicaSet/sampleapi-deployment-498305766
Containers:
  sampleapi:
    Container ID:   docker://19d414c87ebafe1cc99d101ac60f1113533e44c24552c75af4ec197d3d3c9c53
    Image:          mycontainerregistry.azurecr.io/sampleapi:latest
    Image ID:       docker-pullable://mycontainerregistry.azurecr.io/sampleapi@sha256:9635a9df168ef76a6a27cd46cb15620d762657e9b57a5ac2514ba0b9a8f47a8d
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Fri, 27 Jul 2018 00:20:48 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-mj5m1 (ro)
Conditions:
  Type           Status
  Initialized    True
  Ready          True
  PodScheduled   True
Volumes:
  default-token-mj5m1:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-mj5m1
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     <none>
Events:
  Type    Reason                 Age   From                   Message
  ----    ------                 ----  ----                   -------
  Normal  Scheduled              50m   default-scheduler      Successfully assigned sampleapi-deployment-498305766-zzs2z to c103facs9001
  Normal  SuccessfulMountVolume  50m   kubelet, c103facs9001  MountVolume.SetUp succeeded for volume "default-token-mj5m1"
  Normal  Pulling                49m   kubelet, c103facs9001  pulling image "mycontainerregistry.azurecr.io/sampleapi:latest"
  Normal  Pulled                 49m   kubelet, c103facs9001  Successfully pulled image "mycontainerregistry.azurecr.io/sampleapi:latest"
  Normal  Created                49m   kubelet, c103facs9001  Created container
  Normal  Started                49m   kubelet, c103facs9001  Started container

1 个答案:

答案 0 :(得分:0)

在我看来,您的服务未设置为容器上的端口。您已将operator.注释掉。因此,该服务可在端口80上访问,但该服务不知道该端口上的pod的目标。