Skip to content

Instantly share code, notes, and snippets.

@yokawasa
Last active June 10, 2022 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yokawasa/7aae70ef5ac8e7f23fd75cb73d9f161b to your computer and use it in GitHub Desktop.
Save yokawasa/7aae70ef5ac8e7f23fd75cb73d9f161b to your computer and use it in GitHub Desktop.
Service Fabric Mesh: Quickstart with Helloworld app

Service Fabric Mesh: Quickstart with Helloworld app

Setup SF Mesh CLI Locally

# Install the Azure Service Fabric Mesh CLI extension module using following command.
$ az extension add --name mesh

# To update an existing Azure Service Fabric Mesh CLI module, run the following command.
$ az extension update --name mesh

Create Resource Group

RESOURCE_GROUP=rg-sf-mesh
az group create --name $RESOURCE_GROUP --location eastus

Deploy Sample App

$ az mesh deployment create --resource-group $RESOURCE_GROUP --template-uri https://sfmeshsamples.blob.core.windows.net/templates/helloworld/mesh_rp.linux.json --parameters "{'location': {'value': 'eastus'}}"


Deploying . . .
application helloWorldApp has been deployed successfully on network helloWorldNetwork with public ip address 137.135.106.75
To recieve additional information run the following to get the status of the application deployment.
az mesh app show --resource-group rg-sf-mesh --name helloWorldApp

Here is a template for Hello World app - mesh_rp.linux.json

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location": {
      "type": "string",
      "metadata": {
        "description": "Location of the resources."
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2018-07-01-preview",
      "name": "helloWorldNetwork",
      "type": "Microsoft.ServiceFabricMesh/networks",
      "location": "[parameters('location')]",
      "dependsOn": [],
      "properties": {
        "addressPrefix": "10.0.0.4/22",
        "ingressConfig": {
          "layer4": [
            {
              "name": "helloWorldIngress",
              "publicPort": "80",
              "applicationName": "helloWorldApp",
              "serviceName": "helloWorldService",
              "endpointName": "helloWorldListener"
            }
          ]
        }
      }
    },
    {
      "apiVersion": "2018-07-01-preview",
      "name": "helloWorldApp",
      "type": "Microsoft.ServiceFabricMesh/applications",
      "location": "[parameters('location')]",
      "dependsOn": [
        "Microsoft.ServiceFabricMesh/networks/helloWorldNetwork"
      ],
      "properties": {
        "description": "Service Fabric Mesh HelloWorld Application!",
        "services": [
          {
            "type": "Microsoft.ServiceFabricMesh/services",
            "location": "[parameters('location')]",
            "name": "helloWorldService",
            "properties": {
              "description": "Service Fabric Mesh Hello World Service.",
              "osType": "linux",
              "codePackages": [
                {
                  "name": "helloWorldCode",
                  "image": "seabreeze/azure-mesh-helloworld:1.1-alpine",
                  "endpoints": [
                    {
                      "name": "helloWorldListener",
                      "port": "80"
                    }
                  ],
                  "resources": {
                    "requests": {
                      "cpu": "1",
                      "memoryInGB": "1"
                    }
                  }
                },
                {
                  "name": "helloWorldSideCar",
                  "image": "seabreeze/azure-mesh-helloworld-sidecar:1.0-alpine",
                  "resources": {
                    "requests": {
                      "cpu": "1",
                      "memoryInGB": "1"
                    }
                  }
                }
              ],
              "replicaCount": "1",
              "networkRefs": [
                {
                  "name": "[resourceId('Microsoft.ServiceFabricMesh/networks', 'helloWorldNetwork')]"
                }
              ]
            }
          }
        ]
      }
    }
  ]
}

Access the app

Once the application successfully deploys, copy the public IP address for the service endpoint from the CLI output. Open the IP address in a web browser. A web page with the Azure Service Fabric Mesh logo displays.

Manage the app

Check the application details

$ az mesh app show --resource-group $RESOURCE_GROUP --name helloWorldApp

{
  "debugParams": null,
  "description": "Service Fabric Mesh HelloWorld Application!",
  "diagnostics": null,
  "healthState": "Ok",
  "id": "/subscriptions/87c7c7f9-0c9f-47d1-a856-1305a0cbfd7a/resourcegroups/rg-sf-mesh/providers/Microsoft.ServiceFabricMesh/applications/helloWorldApp",
  "location": "eastus",
  "name": "helloWorldApp",
  "provisioningState": "Succeeded",
  "resourceGroup": "rg-sf-mesh",
  "serviceNames": [
    "helloWorldService"
  ],
  "services": null,
  "status": "Ready",
  "statusDetails": null,
  "tags": {},
  "type": "Microsoft.ServiceFabricMesh/applications",
  "unhealthyEvaluation": null
}

See the application logs

$ az mesh code-package-log get --resource-group $RESOURCE_GROUP --application-name helloWorldApp --service-name helloWorldService --replica-name 0 --code-package-name helloWorldCode

{'additional_properties': {}, 'content': '2018-10-21T02:09:02.360340273+00:00 stdout F 10.88.0.1 - - [21/Oct/2018:02:09:02 +0000] "GET / HTTP/1.1" 200 1268 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"\r\n2018-10-21T02:09:02.619903226+00:00 stdout F 10.88.0.1 - - [21/Oct/2018:02:09:02 +0000] "GET /ServiceFabricMesh.svg HTTP/1.1" 200 2138 "http://137.135.106.75/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"\r\n2018-10-21T02:09:02.840202147+00:00 stdout F 2018/10/21 02:09:02 [error] 5#5: *35 open() "/usr/share/nginx/html/sficon.png" failed (2: No such file or directory), client: 10.88.0.1, server: localhost, request: "GET /sficon.png HTTP/1.1", host: "137.135.106.75", referrer: "http://137.135.106.75/"\r\n2018-10-21T02:09:02.840202147+00:00 stdout F 10.88.0.1 - - [21/Oct/2018:02:09:02 +0000] "GET /sficon.png HTTP/1.1" 404 571 "http://137.135.106.75/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36" "-"\r\n2018-10-21T02:09:37.327740433+00:00 stdout F 2018/10/21 02:09:37 [error] 5#5: *43 "/usr/share/nginx/html/computer/index.html" is not found (2: No such file or directory), client: 10.88.0.1, server: localhost, request: "GET /computer/ HTTP/1.1", host: "137.135.107.51", referrer: "http://137.135.107.51:80/computer/"\r\n2018-10-21T02:09:37.327740433+00:00 stdout F 10.88.0.1 - - [21/Oct/2018:02:09:37 +0000] "GET /computer/ HTTP/1.1" 404 571 "http://137.135.107.51:80/computer/" "Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1)" "-"\r\n'}

clean up the resource

az group delete --name $RESOURCE_GROUP

Sample app - container images

A deploy app (Linux Container image) is seabreeze/azure-mesh-helloworld:1.1-alpine ([docker hub page](- https://hub.docker.com/r/seabreeze/azure-mesh-helloworld/)). Its source code is this on Github

LINKS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment