Deploying microservices to Azure Kubernetes Service

duration 1 hour
Git clone to get going right away:
git clone https://github.com/OpenLiberty/guide-cloud-azure.git
Copy Github clone command

Explore how to deploy microservices to Azure Kubernetes Service (AKS) on Microsoft Azure.

What you’ll learn

You will learn how to deploy two microservices in Open Liberty containers to a Kubernetes cluster on Azure Kubernetes Service (AKS).

Kubernetes is an open source container orchestrator that automates many tasks involved in deploying, managing, and scaling containerized applications. If you would like to learn more about Kubernetes, check out the Deploying microservices to Kubernetes guide.

There are different cloud-based solutions for running your Kubernetes workloads. A cloud-based infrastructure enables you to focus on developing your microservices without worrying about low-level infrastructure details for deployment. Using a cloud helps you to easily scale and manage your microservices in a high-availability setup.

Azure offers a managed Kubernetes service called Azure Kubernetes Service (AKS). Using AKS simplifies the process of running Kubernetes on Azure without needing to install or maintain your own Kubernetes control plane. It provides a hosted Kubernetes cluster that you can deploy your microservices to. You will use AKS with an Azure Container Registry (ACR). ACR is a private registry that is used to store and distribute your container images. Note, since AKS is not free, a small cost is associated with running this guide. See the official AKS pricing documentation for more details.

The two microservices you will deploy are called system and inventory. The system microservice returns the JVM system properties of the running container. It also returns the name of the pod in the HTTP header, making replicas easy to distinguish from each other. The inventory microservice adds the properties from the system microservice to the inventory. This demonstrates how communication can be established between pods inside a cluster.

Prerequisites

Before you begin, the following tools need to be installed:

  • Docker: You need a containerization software for building containers. Kubernetes supports various container types, but you will use Docker in this guide. For installation instructions, refer to the official Docker documentation. If you already have Docker installed, make sure to have it running.

  • Azure Subscription: To run this guide, you will need an Azure subscription. Navigate to the Microsoft Azure Purchase Options to create an account with your email and start a Pay-As-You-Go subscription.

  • Azure CLI: You will need to use the Azure Command Line Interface (CLI). See the official Install the Azure CLI documentation for information about setting up the Azure CLI for your platform. To verify that the Azure CLI is installed correctly, run the following command:

    az --version
  • kubectl: You need the Kubernetes command-line tool kubectl to interact with your Kubernetes cluster. If you do not have kubectl installed already, use the Azure CLI to download and install kubectl with the following command:

    az aks install-cli

To begin this guide, make sure that you are logged in to Azure to get access to your subscription:

az login

Getting started

The fastest way to work through this guide is to clone the Git repository and use the projects that are provided inside:

git clone https://github.com/openliberty/guide-cloud-azure.git
cd guide-cloud-azure

The start directory contains the starting project that you will build upon.

The finish directory contains the finished project that you will build.

Managing an Azure Container Registry

To deploy your microservices, you need to create an Azure Container Registry in the same location where your services are deployed, and link the registry to a resource group. Your registry will manage container instances that will be deployed to a Kubernetes cluster.

Creating a resource group

A resource group is an Azure construct to manage a logical collection of resources for your cloud deployments on Azure. You must create a new resource group to manage the resources you need for your Kubernetes deployment.

To create a resource group, an Azure location must be specified. The metadata for your resources are stored at this specified Azure location. If resources are created later without specifying a location, these new resources run in the same region that you specified for creating a resource group.

See the list of available Azure regions for your Azure subscription:

az account list-locations -o table

You will see an output similar to the following:

DisplayName          Latitude    Longitude    Name
-------------------  ----------  -----------  ------------------
Central US           41.5908     -93.6208     centralus
East US              37.3719     -79.8164     eastus
East US 2            36.6681     -78.3889     eastus2
West US              37.783      -122.417     westus
North Central US     41.8819     -87.6278     northcentralus
South Central US     29.4167     -98.5        southcentralus
Canada Central       43.653      -79.383      canadacentral
Canada East          46.817      -71.217      canadaeast
UK South             50.941      -0.799       uksouth
UK West              53.427      -3.084       ukwest
West Central US      40.890      -110.234     westcentralus
West US 2            47.233      -119.852     westus2

The name column specifies the region name that you use to create your resource group.

However, AKS is not available in all regions. Make sure that the region you select is compatible with AKS.

Create a resource group using the az group create command. Remember to replace [location] with a region that is available for your subscription and compatible with AKS.

az group create -l [location] -n guideGroup

You will see an output similar to the following:

{
  "id": "/subscriptions/[subscription-id]/resourceGroups/guideGroup",
  "location": "[location]",
  "managedBy": null,
  "name": "guideGroup",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": null
}

Creating a container registry

Your private container registry manages Docker images that you build in later steps. With the Azure az acr command, create an Azure Container Registry.

az acr create -g guideGroup -n guideRegistry --sku Basic --admin-enabled

In the az acr create command, the -g option specifies the resource group to designate to the container registry. You created this resource group before as guideGroup. The -n option specifies the name of the container registry to be created, which was defined as guideRegistry. The --admin-enabled flag indicates that the admin user is enabled.

The possible Stock Keeping Unit (SKU) values that can be passed into the --sku option are Basic, Standard, and Premium. These different SKU options provide pricing for various levels of capacity and usage. You use a Basic SKU because it is cheaper and the services you deploy have low storage and throughput requirements.

You will see an output similar to the following:

{
  "adminUserEnabled": true,
  "creationDate": "2019-06-05T20:28:09.637994+00:00",
  "id": "/subscriptions/[subscription-id]/resourceGroups/guideGroup/providers/Microsoft.ContainerRegistry/registries/guideRegistry",
  "location": "[location]",
  "loginServer": "guideregistry.azurecr.io",
  "name": "guideRegistry",
  "networkRuleSet": null,
  "provisioningState": "Succeeded",
  "resourceGroup": "guideGroup",
  "sku": {
    "name": "Basic",
    "tier": "Basic"
  },
  "status": null,
  "storageAccount": null,
  "tags": {},
  "type": "Microsoft.ContainerRegistry/registries"
}

Your container registry has a server name of guideregistry.azurecr.io.

Logging into the container registry

You must log in to your Azure Container Registry by using the Azure CLI, to push Docker images to your registry.

az acr login -n guideRegistry

Once you log in, you will see the following message:

Login Succeeded

Uploading images to a container registry

Building your Docker images

The starting Java project, which you can find in the start directory, is a multi-module Maven project. It is made up of the system and inventory microservices. Each microservice exists in its own directory, start/system and start/inventory. Both of these directories contain a Dockerfile, which is necessary for building the Docker images. If you’re unfamiliar with Dockerfiles, check out the Containerizing microservices guide.

Navigate to the start directory and run the following command:

mvn package

Now that your microservices are packaged, build your Docker images using the docker build command. To build your image, you need to have Docker installed and your Docker daemon started.

Run the following commands to build and containerize the application:

docker build -t system:1.0-SNAPSHOT system/.
docker build -t inventory:1.0-SNAPSHOT inventory/.

To verify that the images are built, run the docker images command to list all local Docker images:

docker images

Your two images system and inventory should appear in the list of all Docker images:

REPOSITORY    TAG             IMAGE ID        CREATED          SIZE
inventory     1.0-SNAPSHOT    08fef024e986    4 minutes ago    471MB
system        1.0-SNAPSHOT    1dff6d0b4f31    5 minutes ago    470MB

Pushing the images to a container registry

Pushing the images to a registry allows the cluster to create pods using your container images.

Tag your container images with your registry:

docker tag system:1.0-SNAPSHOT guideregistry.azurecr.io/system:1.0-SNAPSHOT
docker tag inventory:1.0-SNAPSHOT guideregistry.azurecr.io/inventory:1.0-SNAPSHOT

Finally, push your images to the registry:

docker push guideregistry.azurecr.io/system:1.0-SNAPSHOT
docker push guideregistry.azurecr.io/inventory:1.0-SNAPSHOT

Creating a Kubernetes cluster on AKS

Provisioning a cluster

To create your AKS cluster, use the az aks create cluster command. When the cluster is created, the command outputs information about the cluster. You might need to wait while your cluster is being created.

az aks create -g guideGroup -n guideCluster

Running this command creates an AKS cluster that is called guideCluster with the resource group guideGroup.

The option --node-count -c can also be added to this az aks create command to create a cluster with a certain number of nodes in the Kubernetes node pool. By default, if this option is excluded, three nodes are assigned to the node pool.

An AKS cluster requires a service principal, which is an identity that is used to represent a resource in Azure that can be assigned roles and permissions to interact with other resources and the Azure API. The az aks create command automatically generates a service principal to use with your newly created cluster. Optionally, you can manually create a service principal yourself and create a cluster with this new service principal. However, to run this command, your Azure account must have permission access to create service principals.

Merge the credentials of your cluster into your current Kubernetes configuration by using the az aks get-credentials command. The default Kubernetes configuration file that is updated with your cluster credentials is located within the ~/.kube/config filepath.

az aks get-credentials -g guideGroup -n guideCluster

You will see an output similar to the following:

Merged "guideCluster" as current context in /Users/.kube/config

Run the following command to check the status of the available nodes in your AKS cluster:

kubectl get nodes

The kubectl get nodes command outputs information about three nodes, as the cluster was created with the default number of nodes in a node pool. The STATUS of each node is in the Ready state.

NAME                       STATUS   ROLES   AGE     VERSION
aks-nodepool1-21407934-0   Ready    agent   2m25s   v1.12.8
aks-nodepool1-21407934-1   Ready    agent   2m48s   v1.12.8
aks-nodepool1-21407934-2   Ready    agent   2m34s   v1.12.8

Storing registry credentials in a secret

To be able to pull the images from your Azure container registry, the credentials of your registry must be added to your service through a secret.

View the password for your Azure container registry:

az acr credential show -n guideRegistry --query "passwords[0].value" -o tsv

Use the kubectl create secret docker-registry command to create a secret to hold your registry credentials. Replace [password] with the registry password that you viewed with the az acr credential show -n guideRegistry command. The email that is associated with your Docker account replaces [email-address].

kubectl create secret docker-registry guidesecret \
    --docker-server=guideregistry.azurecr.io \
    --docker-username=guideRegistry \
    --docker-password=[password] \
    --docker-email=[email-address]

The secret is successfully created with the following output:

secret/guidesecret created

Deploying microservices to AKS

Creating a deployment definition

Now that your container images are built and you have created a Kubernetes cluster, you can deploy the images using a Kubernetes resource definition.

A Kubernetes resource definition is a yaml file that contains a description of all your deployments, services, or any other resources that you want to deploy. All resources can also be deleted from the cluster by using the same yaml file that you used to deploy them. The kubernetes.yaml resource definition file is provided for you. If you are interested in learning more about the Kubernetes resource definition, check out the Deploying microservices to Kubernetes guide.

Create the kubernetes.yaml.
kubernetes.yaml

kubernetes.yaml

 1apiVersion: apps/v1
 2kind: Deployment
 3metadata:
 4  name: system-deployment
 5  labels:
 6    app: system
 7spec:
 8  selector:
 9    matchLabels:
10      app: system
11  template:
12    metadata:
13      labels:
14        app: system
15    spec:
16      containers:
17      - name: system-container
18        # tag::sysImage[]
19        image: guideregistry.azurecr.io/system:1.0-SNAPSHOT
20        # end::sysImage[]
21        ports:
22        - containerPort: 9080
23      # tag::sysSecret[]
24      imagePullSecrets:
25      - name: guidesecret
26      # end::sysSecret[]
27---
28apiVersion: apps/v1
29kind: Deployment
30metadata:
31  name: inventory-deployment
32  labels:
33    app: inventory
34spec:
35  selector:
36    matchLabels:
37      app: inventory
38  template:
39    metadata:
40      labels:
41        app: inventory
42    spec:
43      containers:
44      - name: inventory-container
45        # tag::invImage[]
46        image: guideregistry.azurecr.io/inventory:1.0-SNAPSHOT
47        # end::invImage[]
48        ports:
49        - containerPort: 9081
50      # tag::invSecret[]
51      imagePullSecrets:
52      - name: guidesecret
53      # end::invSecret[]
54---
55apiVersion: v1
56kind: Service
57metadata:
58  name: system-service
59spec:
60  # tag::sysLoadBalancer[]
61  type: LoadBalancer
62  # end::sysLoadBalancer[]
63  selector:
64    app: system
65  ports:
66  - protocol: TCP
67    port: 9080
68    targetPort: 9080
69---
70apiVersion: v1
71kind: Service
72metadata:
73  name: inventory-service
74spec:
75  # tag::invLoadBalancer[]
76  type: LoadBalancer
77  # end::invLoadBalancer[]
78  selector:
79    app: inventory
80  ports:
81  - protocol: TCP
82    port: 9081
83    targetPort: 9081

The image is the name and tag of the container image that you want to use for the container. The kubernetes.yaml file references the images that you pushed to guideRegistry for the system and inventory repositories. These images can be pulled with the secret that you defined before.

The service that is used to expose your deployments has a type of LoadBalancer. This means you can access these services from IP addresses that forward incoming traffic to your nodepool via a specific port. You can expose your services in other ways such as using a NodePort service type.

Deploying your application

To deploy your microservices to Azure Kubernetes Service, you need Kubernetes to create the contents of the kubernetes.yaml file.

Run the following command to deploy the resources defined in the kubernetes.yaml file:

kubectl create -f kubernetes.yaml

You will see an output similar to the following:

deployment.apps/system-deployment created
deployment.apps/inventory-deployment created
service/system-service created
service/inventory-service created

Run the following command to check the status of your pods:

kubectl get pods

If all the pods are healthy and running, you see an output similar to the following:

NAME                                    READY     STATUS    RESTARTS   AGE
system-deployment-6bd97d9bf6-4ccds      1/1       Running   0          15s
inventory-deployment-645767664f-nbtd9   1/1       Running   0          15s

Making requests to the microservices

You need the external IP addresses that are associated with the system and inventory services to try out your microservices.

Take note of the EXTERNAL-IP in the output of the following commands. It is the hostname that you will later substitute into [EXTERNAL-IP] to access the system and inventory services.

View the information of the system service to see its EXTERNAL-IP address:

kubectl get service/system-service

You need to wait a while for the EXTERNAL-IP to change from <pending> to an IP address.

NAME                TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)           AGE
system-service      LoadBalancer   10.0.27.66     <pending>       9080:32436/TCP    26s
NAME                TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)           AGE
system-service      LoadBalancer   10.0.27.66     23.99.223.10    9080:32436/TCP    74s

View the information of the inventory service to see its EXTERNAL-IP address:

kubectl get service/inventory-service

You will need to wait a while for the EXTERNAL-IP to change from <pending> to an IP address.

NAME                TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)           AGE
inventory-service   LoadBalancer   10.0.103.223   <pending>       9081:32739/TCP    69s
NAME                TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)           AGE
inventory-service   LoadBalancer   10.0.103.223   168.61.174.136  9081:32739/TCP    2m8s

To access your microservices, point your browser to the following URLs, substituting the appropriate EXTERNAL-IP hostnames for the system and inventory services:

  • http://[system-EXTERNAL-IP]:9080/system/properties

  • http://[inventory-EXTERNAL-IP]:9081/inventory/systems

In the first URL, you see a result in JSON format with the system properties of the container JVM. The second URL returns an empty list, which is expected because no system properties are stored in the inventory yet.

Point your browser to the http://[inventory-EXTERNAL-IP]:9081/inventory/systems/[system-EXTERNAL-IP] URL. When you visit this URL, these system properties are automatically stored in the inventory. Go back to http://[inventory-EXTERNAL-IP]:9081/inventory/systems and you see a new entry for [system-EXTERNAL-IP].

Testing the microservices

A few tests are included for you to test the basic functionality of the microservices. If a test failure occurs, then you might have introduced a bug into the code. To run the tests, wait for all pods to be in the ready state before you proceed further.

pom.xml

  1<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  2    <modelVersion>4.0.0</modelVersion>
  3
  4    <parent>
  5        <groupId>net.wasdev.wlp.maven.parent</groupId>
  6        <artifactId>liberty-maven-app-parent</artifactId>
  7        <version>RELEASE</version>
  8    </parent>
  9
 10    <groupId>io.openliberty.guides</groupId>
 11    <artifactId>guide-cloud-azure</artifactId>
 12    <version>1.0-SNAPSHOT</version>
 13    <packaging>pom</packaging>
 14
 15    <properties>
 16        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 17        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 18        <maven.compiler.source>1.8</maven.compiler.source>
 19        <maven.compiler.target>1.8</maven.compiler.target>
 20
 21        <!-- Plugins -->
 22        <version.maven-war-plugin>3.2.2</version.maven-war-plugin>
 23        <version.download-maven-plugin>1.4.0</version.download-maven-plugin>
 24        <version.maven-surefire-plugin>3.0.0-M1</version.maven-surefire-plugin>
 25        <version.maven-failsafe-plugin>3.0.0-M1</version.maven-failsafe-plugin>
 26        <!-- OpenLiberty runtime -->
 27        <version.openliberty-runtime>RELEASE</version.openliberty-runtime>
 28        <!-- tag::sysHttpPort[] -->
 29        <sys.service.http.port>9080</sys.service.http.port>
 30        <!-- end::sysHttpPort[] -->
 31        <sys.service.https.port>9443</sys.service.https.port>
 32        <!-- tag::invHttpPort[] -->
 33        <inv.service.http.port>9081</inv.service.http.port>
 34        <!-- end::invHttpPort[] -->
 35        <inv.service.https.port>9444</inv.service.https.port>
 36        <!-- Default test properties -->
 37        <!-- tag::sysKubeService[] -->
 38        <system.ip>system-service</system.ip>
 39        <!-- end::sysKubeService[] -->
 40        <!-- tag::invKubeService[] -->
 41        <inventory.ip>inventory-service</inventory.ip>
 42        <!-- end::invKubeService[] -->
 43    </properties>
 44
 45    <!-- Shared dependencies. -->
 46    <dependencyManagement>
 47        <dependencies>
 48            <dependency>
 49                <groupId>io.openliberty.features</groupId>
 50                <artifactId>features-bom</artifactId>
 51                <version>RELEASE</version>
 52                <type>pom</type>
 53                <scope>import</scope>
 54            </dependency>
 55            <!-- For tests -->
 56            <dependency>
 57                <groupId>junit</groupId>
 58                <artifactId>junit</artifactId>
 59                <version>4.12</version>
 60                <scope>test</scope>
 61            </dependency>
 62            <dependency>
 63                <groupId>org.apache.cxf</groupId>
 64                <artifactId>cxf-rt-rs-client</artifactId>
 65                <version>3.2.6</version>
 66                <scope>test</scope>
 67            </dependency>
 68            <dependency>
 69                <groupId>org.apache.cxf</groupId>
 70                <artifactId>cxf-rt-rs-extension-providers</artifactId>
 71                <version>3.2.6</version>
 72                <scope>test</scope>
 73            </dependency>
 74            <dependency>
 75                <groupId>org.glassfish</groupId>
 76                <artifactId>javax.json</artifactId>
 77                <version>1.0.4</version>
 78                <scope>test</scope>
 79            </dependency>
 80            <dependency>
 81                <groupId>org.apache.commons</groupId>
 82                <artifactId>commons-lang3</artifactId>
 83                <version>3.0</version>
 84                <scope>compile</scope>
 85            </dependency>
 86            <!-- Support for JDK 9 and above -->
 87            <dependency>
 88                <groupId>javax.xml.bind</groupId>
 89                <artifactId>jaxb-api</artifactId>
 90                <version>2.3.1</version>
 91                <scope>provided</scope>
 92            </dependency>
 93            <dependency>
 94                <groupId>com.sun.xml.bind</groupId>
 95                <artifactId>jaxb-core</artifactId>
 96                <version>2.3.0.1</version>
 97                <scope>provided</scope>
 98            </dependency>
 99            <dependency>
100                <groupId>com.sun.xml.bind</groupId>
101                <artifactId>jaxb-impl</artifactId>
102                <version>2.3.2</version>
103                <scope>provided</scope>
104            </dependency>
105            <dependency>
106                <groupId>javax.activation</groupId>
107                <artifactId>activation</artifactId>
108                <version>1.1.1</version>
109                <scope>provided</scope>
110            </dependency>
111        </dependencies>
112    </dependencyManagement>
113
114    <profiles>
115        <!-- mvn.cmd for windows systems -->
116        <profile>
117            <id>windowsExtension</id>
118            <activation>
119                <os><family>Windows</family></os>
120            </activation>
121            <properties>
122                <mvn.extension>.cmd</mvn.extension>
123            </properties>
124        </profile>
125        <!-- just mvn for other systems -->
126        <profile>
127            <id>nonWindowsExtension</id>
128            <activation>
129                <os><family>!Windows</family></os>
130            </activation>
131            <properties>
132                <mvn.extension></mvn.extension>
133            </properties>
134        </profile>
135    </profiles>
136
137    <build>
138        <pluginManagement>
139            <plugins>
140                <plugin>
141                    <groupId>org.apache.maven.plugins</groupId>
142                    <artifactId>maven-war-plugin</artifactId>
143                    <version>${version.maven-war-plugin}</version>
144                    <configuration>
145                        <failOnMissingWebXml>false</failOnMissingWebXml>
146                        <packagingExcludes>pom.xml</packagingExcludes>
147                    </configuration>
148                </plugin>
149                <!-- Liberty Maven plugin -->
150                <plugin>
151                    <groupId>net.wasdev.wlp.maven.plugins</groupId>
152                    <artifactId>liberty-maven-plugin</artifactId>
153                    <configuration>
154                        <assemblyArtifact>
155                            <groupId>io.openliberty</groupId>
156                            <artifactId>openliberty-runtime</artifactId>
157                            <version>RELEASE</version>
158                            <type>zip</type>
159                        </assemblyArtifact>
160                        <!-- tag::packageFile[] -->
161                        <packageFile>
162                            ${project.build.directory}/${app.name}.tar.gz
163                        </packageFile>
164                        <!-- end::packageFile[] -->
165                    </configuration>
166                </plugin>
167                <!-- Plugin to run unit tests -->
168                <plugin>
169                    <groupId>org.apache.maven.plugins</groupId>
170                    <artifactId>maven-surefire-plugin</artifactId>
171                    <version>${version.maven-surefire-plugin}</version>
172                    <executions>
173                        <execution>
174                            <phase>test</phase>
175                            <id>default-test</id>
176                            <configuration>
177                                <excludes>
178                                    <exclude>**/it/**</exclude>
179                                </excludes>
180                                <reportsDirectory>
181                                    ${project.build.directory}/test-reports/unit
182                                </reportsDirectory>
183                            </configuration>
184                        </execution>
185                    </executions>
186                </plugin>
187                <!-- Plugin to run functional tests -->
188                <plugin>
189                    <groupId>org.apache.maven.plugins</groupId>
190                    <artifactId>maven-failsafe-plugin</artifactId>
191                    <version>${version.maven-failsafe-plugin}</version>
192                    <executions>
193                        <execution>
194                            <phase>integration-test</phase>
195                            <id>integration-test</id>
196                            <goals>
197                                <goal>integration-test</goal>
198                            </goals>
199                            <configuration>
200                                <includes>
201                                    <include>**/it/**</include>
202                                </includes>
203                                <systemPropertyVariables>
204                                    <system.kube.service>
205                                        ${system.ip}
206                                    </system.kube.service>
207                                    <inventory.kube.service>
208                                        ${inventory.ip}
209                                    </inventory.kube.service>
210                                    <sys.http.port>
211                                        ${sys.service.http.port}
212                                    </sys.http.port>
213                                    <inv.http.port>
214                                        ${inv.service.http.port}
215                                    </inv.http.port>
216                                </systemPropertyVariables>
217                            </configuration>
218                        </execution>
219                        <execution>
220                            <id>verify-results</id>
221                            <goals>
222                                <goal>verify</goal>
223                            </goals>
224                        </execution>
225                    </executions>
226                    <configuration>
227                        <summaryFile>
228                        ${project.build.directory}/test-reports/it/failsafe-summary.xml
229                        </summaryFile>
230                        <reportsDirectory>
231                            ${project.build.directory}/test-reports/it
232                        </reportsDirectory>
233                    </configuration>
234                </plugin>
235            </plugins>
236        </pluginManagement>
237    </build>
238
239    <modules>
240        <module>system</module>
241        <module>inventory</module>
242    </modules>
243
244</project>

The default properties that are defined in the pom.xml file are:

PropertyDescription

system.ip

Name of the Kubernetes Service wrapping the system pods, system-service by default.

inventory.ip

Name of the Kubernetes Service wrapping the inventory pods, inventory-service by default.

sys.service.http.port

The HTTP port for the Kubernetes Service system-service, 9080 by default.

inv.service.http.port

The HTTP port of the Kubernetes Service inventory-service, 9081 by default.

Running the tests

Run the Maven verify goal to test your microservices by replacing the [system-EXTERNAL-IP] and [inventory-EXTERNAL-IP] with the value determined in the previous section.

mvn verify -Ddockerfile.skip=true -Dsystem.ip=[system-EXTERNAL-IP] -Dinventory.ip=[inventory-EXTERNAL-IP]

The dockerfile.skip parameter is set to true to skip building a new container image.

If the tests pass, you will see an output similar to the following for each service:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running it.io.openliberty.guides.system.SystemEndpointTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.673 sec - in it.io.openliberty.guides.system.SystemEndpointTest

Results:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running it.io.openliberty.guides.inventory.InventoryEndpointTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.222 sec - in it.io.openliberty.guides.inventory.InventoryEndpointTest

Results:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Tearing down the environment

It is important to clean up your resources when you are finished with the guide so that you do not incur extra charges for ongoing usage.

When you no longer need your deployed microservices, you can delete all Kubernetes resources by running the kubectl delete command:

kubectl delete -f kubernetes.yaml

Since you are done testing your cluster, clean up all of its related sources using the az group delete command. This command removes the resource group, container service, and all related resources:

az group delete -g guideGroup --yes --no-wait

Great work! You’re done!

You have just deployed two microservices running in Open Liberty to Azure Kubernetes Service (AKS). You also learned how to use kubectl to deploy your microservices on a Kubernetes cluster.

Guide Attribution

Deploying microservices to Azure Kubernetes Service by Open Liberty is licensed under CC BY-ND 4.0

Copied to clipboard
Copy code block
Copy file contents
Git clone this repo to get going right away:
git clone https://github.com/OpenLiberty/guide-cloud-azure.git
Copy github clone command
Copied to clipboard

Nice work! Where to next?

What did you think of this guide?

Extreme Dislike Dislike Like Extreme Like

What could make this guide better?

Raise an issue to share feedback

Create a pull request to contribute to this guide

Need help?

Ask a question on Stack Overflow

Like Open Liberty? Star our repo on GitHub.

Star