Giter Site home page Giter Site logo

azure-app-service-on-kubernetes-with-azure-arc-sample's Introduction

App Service and API Management on Arc-enabled Kubernetes sample

Introduction

The aim of this project is to illustrate a simple Azure App Service example running on an ARC-enabled Kubernetes cluster, with APIs exposed using an external API Management Gateway in the Kubernetes cluster. This Web App allows user to read and create a rating of a product. It is a single web page that calls APIs hosted by the server component. When deployed to Azure, the API Management Gateway exposes some of the APIs from within the cluster.

Architecture Diagram

Background reading:

Local Build and Test

Visual Studio

  1. Open Ratings.sln in Visual Studio.
  2. Press f5 to debug Ratings.Server project.
  3. A browser should open at the url https://localhost:44344/

Visual Studio Code

  1. Open the folder you cloned in VS Code.
  2. Re-open the window in a dev container. You'll need Docker and the Remote Development Extension installed. This container has all the tools and cli extensions you'll need preinstalled. If you can't open the dev container, check ./devcontainer/Dockerfile for the prerequisites.
  3. Press f5 - you may ignore any warnings or errors regarding the webasm debugging extension if you already have it installed.
  4. Open a browser at the url https://locahost:5000

Follow the on screen instructions to add or view ratings.

Postman

  1. Install Postman and open it.

  2. Disable SSL certificate verification: From File > Settings (General tab), disable SSL certificate verification. (Please remember to re-enable SSL certificate verification after testing the api.)

  3. Send new GET request to https://localhost:44344/ratings

  4. Check that the result returns all existing ratings in a memory.

  5. Perform a GET request for a specific rating by changing the URI to https://localhost:44344/ratings/book.

  6. Create a new rating by doing a POST request to https://localhost:44344/ratings using the following body (with Content-Type set to application/json):

    {
        "id":"ice_cream",
        "rating":5,
        "userNotes":"Good choice"
    }

Swagger

  1. Open the Swagger endpoint by doing one of the following:

    1. Run the app in either Visual Studio or Visual Studio Code, and navigate to the '/swagger' endpoint in your browser or click on the Swagger link in the top right corner of any page.
    2. Open the app in Visual Studio, set Debug Profile to Swagger, and press f5
  2. Follow the instructions on the Swagger interface to test GET requests.

  3. Create a new rating by doing a POST request using the following body:

    {
        "id":"ice_cream",
        "rating":5,
        "userNotes":"Good choice"
    }

Deploy to Azure

Prepare environment

  1. Open the folder you cloned in VS Code.

  2. Re-open the window in a dev container. You'll need Docker and the Remote Development Extension installed. This container has all the tools and cli extensions you'll need preinstalled. If you can't open the dev container, check ./devcontainer/Dockerfile for the prerequisites.

    [!TIP] Windows users may face an error while opening the dev container due to Windows style newline characters being added that are not recognized by the bash script from the dev container while cloning the repo. To fix this run 'git config --global core.autocrlf input' in the admin mode. You can find more information here.

    [!TIP] If using WSL1 or Docker without the WSL backend:

    1. Make sure that Docker setting 'Expose daemon on tcp://localhost:2375 without TLS' is enabled, so the docker daemon is running in the container.
    2. Uncomment the line # ENV DOCKER_HOST=tcp://host.docker.internal:2375 in the ./.devcontainer/Dockerfile.
    3. Comment out the mounts section in teh ./.devcontainer/devcontainer.json file.
  3. Open the integrated PowerShell 7 terminal (pwsh)

  4. Log into your Azure subscription using 'az login'.

  5. Ensure you are in the /env directory.

  6. To enable the necessary resource providers in your subscription run

    ./deployFeatureRegister.ps1
  7. Update the basename variable of the deployment in the file setVariables.ps1 and run it.

    [!TIP] Avoid special characters in your namings, as some of the commands support only numbers, characters, '.' and '-'.

    ./setVariables.ps1
  8. Create a compliant AKS cluster, an Azure Container Registry instance, an Application Insights Monitoring resource, a public static IP address and connect the cluster to Arc

    ./provisionBaseInfra.ps1

Provision Web App

  1. Provision your App Service Environment into your Kubernetes cluster

    ./provisionAppServiceInfra.ps1
  2. Build and deploy the Web app from an image stored in the Azure Container Registry into the App Service Kube Environment

    [!NOTE] The argument v1 is used for the build id of the image - you can override this with any value.

    ./deployAppService.ps1 v1

    The script will output the url of your deployed website.

Provision API Management

Provision an API Management instance in Azure, and a self hosted gateway in your Kubernetes cluster.

Note

It may take up to 40 minutes to create an API Management service instance. It is safe to rerun the script in case of a timeout.

./deployAPIM.ps1

The script will output the Azure Portal url of the gateway, and the url of the deployed api

Test API Management in Azure

The gateway is deployed as a LoadBalancer Kubernetes service. We can make requests to the external ip and port exposed by the service.

# view the service details
kubectl get services -n ${apimNamespace}

# make api request
Write-Host $(Invoke-WebRequest -Uri $apiUrl).Content

You can also view the logs of the pod hosting the gateway - this is useful when troubleshooting a service that won't accept connections.

$podName = kubectl get pods -n ${apimNamespace} -o name
kubectl logs $podName -n ${apimNamespace}  

Resources

azure-app-service-on-kubernetes-with-azure-arc-sample's People

Contributors

hannesne avatar microsoft-github-operations[bot] avatar microsoftopensource avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.