首页 > 解决方案 > 如何使用部署在 Azure Kubernetes 服务中的容器化应用从 Postman 访问 API

问题描述

我使用 Node 和 Express 创建了一个示例 API 应用程序,以进行容器化并部署到 Azure Kubernetes 服务 (AKS)。但是,我无法通过从已部署的 service.yml 生成的外部 API 访问 API 端点。

我利用 AKS 中的部署中心将我的应用程序部署到 AKS 并生成相关的 deployment.yml 和 service.yml。以下是包含外部 IP 的运行服务。

在此处输入图像描述

以下是邮递员的回复。我尝试过使用或不使用端口号和 IP 地址,kubectl get endpoints但无济于事。请求最终会超时,无法访问 api。

在此处输入图像描述

以下是dockerfile配置

在此处输入图像描述

我曾尝试四处寻找解决方案,但无法解决。如果您遇到类似的问题并能够分享您的经验,我将不胜感激,谢谢。

标签: azurekubernetesazure-aksazure-container-registry

解决方案


From client machine where kubectl is installed do

kubectl get pods -o wide -n restapicluster5ca2

this will give you all the pods with the ip of the Pods

kubectl describe svc restapicluster-bb91 -n restapicluster5ca2

this will give details about the service and then check LoadBalancer Ingress: for the external IP address, Port: for the port to access, TargetPort: the port on the containers to access i.e 5000 in your case, Endpoints: to verify if all IP of the pod with correct port i.e 5000 is displaying or not.

Log into any of the machines in the AKS cluster do the following

curl [CLUSTER-IP]:[PORT]/api/posts i.e curl 10.-.-.67:5000

check if you get the response.

For reference to use kubectl locally with AKS cluster check the links below

  1. https://docs.microsoft.com/en-us/azure/aks/kubernetes-walkthrough
  2. https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest

推荐阅读