简体   繁体   English

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

[英]Cannot access Web API deployed in Azure ACS Kubernetes Cluster

Please help.请帮忙。 I am trying to deploy a web API to Azure ACS Kubernetes cluster, it is a simple web API created in VSTS and the result should be like this: { "value1", "value2" } .我正在尝试将 Web API 部署到 Azure ACS Kubernetes 集群,它是一个在 VSTS 中创建的简单 Web API,结果应该是这样的: { "value1", "value2" }

I plan to make the type as Cluster-IP but I want to test and access it first that is why this is LoadBalancer , the pods is running and no restart (I think it's good).我计划将类型设为 Cluster-IP,但我想先测试并访问它,这就是为什么这是LoadBalancer ,pod 正在运行并且没有重新启动(我认为这很好)。

The guide I'm following is: Running Web API using Docker and Kubernetes我遵循的指南是: 使用 Docker 和 Kubernetes 运行 Web API

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

When I tried to browse the IP 102.51.223.6/api/values it says:当我尝试浏览 IP 102.51.223.6/api/values它说:

"This site can't be reached" “无法访问此站点”

service.yaml服务.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部署.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

It seems like to me that your service isn't set to a port on the container.在我看来,您的服务未设置为容器上的端口。 You have your targetPort commented out.您已将targetPort注释掉。 So the service is reachable on port 80 but the service doesn't know to target the pod on that port.因此该服务可在端口 80 上访问,但该服务不知道将 pod 定位到该端口上。

You will need to start the service which exposes the internal port to some external Ip:port that can be used in your browser to access the service.您将需要启动该服务,该服务将内部端口暴露给某些可在浏览器中使用以访问该服务的外部 Ip:port。 try this after deploying your deployment and service yml files:在部署部署和服务yml文件后尝试此操作:

kubectl service sampleapi-service

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用Azure CICD管道访问部署在Azure ACS Kubernetes群集中的应用程序 - Cannot access application deployed in Azure ACS Kubernetes Cluster using Azure CICD Pipeline 使用Azure 2.0 CLI设置Azure Kubernetes ACS群集 - Provision Azure Kubernetes ACS cluster using Azure 2.0 CLI 更新ACS Kubernetes集群 - Renewing ACS Kubernetes cluster 在Azure Kubernetes服务(AKS)上部署的Web应用程序的访问日志生成 - Access Log generation of deployed web application on Azure Kubernetes Service (AKS) 是否可以使用Azure API Management和Azure ACS(kubernetes)作为前端和后端? - Is it possible to use Azure API Management and Azure ACS (kubernetes) as frontend and backend? Azure ACS Kubernetes Windows Containers延迟了对Internet的访问 - Azure ACS Kubernetes Windows Containers delayed access to internet 将Azure ACS(访问控制服务)与ASP.NET Web API一起使用 - Using Azure ACS (Access Control Service) with ASP.NET Web API Azure AKS - 无法从部署在 Cluster1 中 Pod1 上的另一个应用程序访问部署在 Cluster2 中 Pod2 上的应用程序 - Azure AKS - Cannot access application deployed on a Pod2 in Cluster2 from another application deployed on Pod1 in Cluster1 Azure ACS(Kubernetes)的Alpha选项 - Alpha options for Azure ACS (Kubernetes) 没有反映Azure Azure ACS-K8S群集中的Kubernetes-dashboard映像更新 - Updating kubernetes-dashboard image in a Azure acs-k8s cluster is not getting reflected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM