简体   繁体   中英

How to access API from Postman with containerized app deployed in Azure Kubernetes Service

I have created a sample API application with Node and Express to be containerized and deployed into Azure Kubernetes Services (AKS). However, I was unable to access the API endpoint through the external API generated from the service.yml that was deployed.

I have made use of deployment center within AKS to deploy my application to AKS and generate the relevant deployment.yml and service.yml. The following is the services running containing the external IP.

在此处输入图片说明

The following is the response from postman. I have tried with or without port number and ip address from kubectl get endpoints but to no avail. The request will timeout eventually and unable to access the api.

在此处输入图片说明

The following is the dockerfile config

在此处输入图片说明

I have tried searching around for solutions, how it was not possible to resolve. I would greatly appreciate if you have encountered similar issues and able to share your experience, thank you.

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 ie 5000 in your case, Endpoints: to verify if all IP of the pod with correct port ie 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

As I see it you need to bring ingress in front of your service. Folks use NgInx etc. for that.

If you want to stay "pure" Azure you could use AGIC - Application Gateway Ingress Controller and annotate your service to have it exposed over AppGw. You could also spin up your own custom AppGw and hook it up with the AKS Service/LoadBalancer IP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM