Skip to content

Commit c6337b5

Browse files
authored
Merge pull request #263902 from KarlErickson/josefree-main-262852
edit "update to remove confusion and add powershell #262852"
2 parents fcb5519 + 79b5f12 commit c6337b5

File tree

3 files changed

+125
-35
lines changed

3 files changed

+125
-35
lines changed

articles/aks/howto-deploy-java-liberty-app.md

Lines changed: 125 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
title: Deploy a Java application with Open Liberty/WebSphere Liberty on an Azure Kubernetes Service (AKS) cluster
33
recommendations: false
44
description: Deploy a Java application with Open Liberty/WebSphere Liberty on an Azure Kubernetes Service (AKS) cluster
5+
author: KarlErickson
6+
ms.author: edburns
57
ms.topic: how-to
68
ms.date: 12/21/2022
79
keywords: java, jakartaee, javaee, microprofile, open-liberty, websphere-liberty, aks, kubernetes
@@ -31,7 +33,7 @@ This article is intended to help you quickly get to deployment. Before going to
3133
* This article requires at least version 2.31.0 of Azure CLI. If using Azure Cloud Shell, the latest version is already installed.
3234

3335
> [!NOTE]
34-
> This guidance can also be executed from a local developer command line with Azure CLI installed. To learn how to install the Azure CLI, see [How to install the Azure CLI](/cli/azure/install-azure-cli).
36+
> This guidance can also be executed from a local developer command line with Azure CLI installed. To learn how to install the Azure CLI, see [How to install the Azure CLI](/cli/azure/install-azure-cli).
3537
3638
* If running the commands in this guide locally (instead of Azure Cloud Shell):
3739
* Prepare a local machine with Unix-like operating system installed (for example, Ubuntu, Azure Linux, macOS, Windows Subsystem for Linux).
@@ -45,19 +47,28 @@ This article is intended to help you quickly get to deployment. Before going to
4547
The following steps guide you to create a Liberty runtime on AKS. After completing these steps, you have an Azure Container Registry and an Azure Kubernetes Service cluster for deploying your containerized application.
4648

4749
1. Visit the [Azure portal](https://portal.azure.com/). In the search box at the top of the page, type *IBM WebSphere Liberty and Open Liberty on Azure Kubernetes Service*. When the suggestions start appearing, select the one and only match that appears in the **Marketplace** section. If you prefer, you can go directly to the offer with this shortcut link: [https://aka.ms/liberty-aks](https://aka.ms/liberty-aks).
50+
4851
1. Select **Create**.
49-
1. In the **Basics** pane, create a new resource group. Because resource groups must be unique within a subscription, pick a unique name. An easy way to have unique names is to use a combination of your initials, today's date, and some identifier. For example, `ejb0913-java-liberty-project-rg`. Select *East US* as **Region**. Select **Next** to **AKS** pane.
50-
1. This pane allows you to select an existing AKS cluster and Azure Container Registry (ACR), instead of causing the deployment to create a new one, if desired. This capability enables you to use the sidecar pattern, as shown in the [Azure architecture center](/azure/architecture/patterns/sidecar). You can also adjust the settings for the size and number of the virtual machines in the AKS node pool. Leave all other values at the defaults and select **Next** to **Load balancing** pane.
51-
1. Next to **Connect to Azure Application Gateway?** select **Yes**. This section lets you customize the following deployment options.
52-
1. You can customize the virtual network and subnet into which the deployment will place the resources. Leave these values at their defaults.
53-
1. You can provide the TLS/SSL certificate presented by the Azure Application Gateway. Leave the values at the default to cause the offer to generate a self-signed certificate. Don't go to production using a self-signed certificate. For more information about self-signed certificates, see [Create a self-signed public certificate to authenticate your application](../active-directory/develop/howto-create-self-signed-certificate.md).
54-
1. You can enable cookie based affinity, also known as sticky sessions. We want sticky sessions enabled for this article, so ensure this option is selected.
55-
![Screenshot of the enable cookie-based affinity checkbox.](./media/howto-deploy-java-liberty-app/enable-cookie-based-affinity.png)
56-
1. Select **Next** to **Operator and application** pane. This quickstart uses all defaults in this pane. However, it lets you customize the following deployment options.
52+
53+
1. In the **Basics** pane:
54+
55+
1. Create a new resource group. Because resource groups must be unique within a subscription, pick a unique name. An easy way to have unique names is to use a combination of your initials, today's date, and some identifier. For example, `ejb0913-java-liberty-project-rg`.
56+
1. Select *East US* as **Region**.
57+
58+
1. Select **Next**, enter the **AKS** pane. This pane allows you to select an existing AKS cluster and Azure Container Registry (ACR), instead of causing the deployment to create a new one, if desired. This capability enables you to use the sidecar pattern, as shown in the [Azure architecture center](/azure/architecture/patterns/sidecar). You can also adjust the settings for the size and number of the virtual machines in the AKS node pool. Leave all other values at the defaults.
59+
60+
1. Select **Next**, enter the **Load Balancing** pane. Next to **Connect to Azure Application Gateway?** select **Yes**. This section lets you customize the following deployment options.
61+
62+
1. You can customize the **virtual network** and **subnet** into which the deployment will place the resources. Leave these values at their defaults.
63+
1. You can provide the **TLS/SSL certificate** presented by the Azure Application Gateway. Leave the values at the default to cause the offer to generate a self-signed certificate. Don't go to production using a self-signed certificate. For more information about self-signed certificates, see [Create a self-signed public certificate to authenticate your application](../active-directory/develop/howto-create-self-signed-certificate.md).
64+
1. You can select **Enable cookie based affinity**, also known as sticky sessions. We want sticky sessions enabled for this article, so ensure this option is selected.
65+
66+
1. Select **Next**, enter the **Operator and application** pane. This quickstart uses all defaults in this pane. However, it lets you customize the following deployment options.
67+
5768
1. You can deploy WebSphere Liberty Operator by selecting **Yes** for option **IBM supported?**. Leaving the default **No** deploys Open Liberty Operator.
5869
1. You can deploy an application for your selected Operator by selecting **Yes** for option **Deploy an application?**. Leaving the default **No** doesn't deploy any application.
59-
1. Select **Review + create** to validate your selected options.
60-
1. When you see the message **Validation Passed**, select **Create**. The deployment may take up to 20 minutes.
70+
71+
1. Select **Review + create** to validate your selected options. In the ***Review + create** pane, when you see **Create** light up after validation pass, select **Create**. The deployment may take up to 20 minutes.
6172

6273
## Capture selected information from the deployment
6374

@@ -75,9 +86,17 @@ If you navigated away from the **Deployment is in progress** page, the following
7586
1. Using the same copy technique as with the preceding values, save aside the values for the following outputs:
7687

7788
* `cmdToConnectToCluster`
78-
* `appDeploymentTemplateYaml`
89+
* `appDeploymentTemplateYaml` if you select **No** to **Deploy an application?** when deploying the Marketplace offer; or `appDeploymentYaml` if you select **yes** to **Deploy an application?**.
90+
91+
### [Bash](#tab/in-bash)
92+
93+
Paste the value of `appDeploymentTemplateYaml` or `appDeploymentYaml` into a Bash shell, append `| grep secretName`, and execute. This command will output the Ingress TLS secret name, such as `- secretName: secret785e2c`. Save aside the value for `secretName` from the output.
94+
95+
### [PowerShell](#tab/in-powershell)
96+
97+
Paste the quoted string in `appDeploymentTemplateYaml` or `appDeploymentYaml` into a PowerShell, append `| ForEach-Object { [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($_)) } | Select-String "secretName"`, and execute. This command will output the Ingress TLS secret name, such as `- secretName: secret785e2c`. Save aside the value for `secretName` from the output.
7998

80-
1. Paste the value of `appDeploymentTemplateYaml` into a Bash shell, append `| grep secretName`, and execute. This command will output the Ingress TLS secret name, such as `- secretName: secret785e2c`. Save aside the value for `secretName` from the output.
99+
---
81100

82101
These values will be used later in this article. Note that several other useful commands are listed in the outputs.
83102

@@ -97,7 +116,7 @@ The following steps guide you through creating an Azure SQL Database single data
97116
>
98117
> At the **Networking** step, set **Connectivity method** to **Public endpoint**, **Allow Azure services and resources to access this server** to **Yes**, and **Add current client IP address** to **Yes**.
99118
>
100-
> ![Screenshot of configuring SQL database networking.](./media/howto-deploy-java-liberty-app/create-sql-database-networking.png)
119+
> :::image type="content" source="media/howto-deploy-java-liberty-app/create-sql-database-networking.png" alt-text="Screenshot of the Azure portal that shows the Networking tab of the Create SQL Database page with the Connectivity method and Firewall rules settings highlighted." lightbox="media/howto-deploy-java-liberty-app/create-sql-database-networking.png":::
101120
102121
Now that the database and AKS cluster have been created, we can proceed to preparing AKS to host your Open Liberty application.
103122

@@ -111,7 +130,7 @@ Clone the sample code for this guide. The sample is on [GitHub](https://github.c
111130

112131
There are a few samples in the repository. We'll use *java-app/*. Here's the file structure of the application.
113132

114-
```azurecli-interactive
133+
```bash
115134
git clone https://github.com/Azure-Samples/open-liberty-on-aks.git
116135
cd open-liberty-on-aks
117136
git checkout 20240109
@@ -151,23 +170,47 @@ In directory *liberty/config*, the *server.xml* file is used to configure the DB
151170

152171
Now that you've gathered the necessary properties, you can build the application. The POM file for the project reads many variables from the environment. As part of the Maven build, these variables are used to populate values in the YAML files located in *src/main/aks*. You can do something similar for your application outside Maven if you prefer.
153172

173+
### [Bash](#tab/in-bash)
174+
154175
```bash
155176
cd <path-to-your-repo>/java-app
156177

157178
# The following variables will be used for deployment file generation into target.
158-
export LOGIN_SERVER=<Azure_Container_Registry_Login_Server_URL>
159-
export REGISTRY_NAME=<Azure_Container_Registry_Name>
160-
export USER_NAME=<Azure_Container_Registry_Username>
161-
export PASSWORD=<Azure_Container_Registry_Password>
162-
export DB_SERVER_NAME=<Server name>.database.windows.net
163-
export DB_NAME=<Database name>
164-
export DB_USER=<Server admin login>@<Server name>
165-
export DB_PASSWORD=<Server admin password>
166-
export INGRESS_TLS_SECRET=<Ingress TLS secret name>
179+
export LOGIN_SERVER=<Azure-Container-Registry-Login-Server-URL>
180+
export REGISTRY_NAME=<Azure-Container-Registry-name>
181+
export USER_NAME=<Azure-Container-Registry-username>
182+
export PASSWORD=<Azure-Container-Registry-password>
183+
export DB_SERVER_NAME=<server-name>.database.windows.net
184+
export DB_NAME=<database-name>
185+
export DB_USER=<server-admin-login>@<server-name>
186+
export DB_PASSWORD=<server-admin-password>
187+
export INGRESS_TLS_SECRET=<ingress-TLS-secret-name>
167188

168189
mvn clean install
169190
```
170191

192+
### [PowerShell](#tab/in-powershell)
193+
194+
```powershell
195+
cd <path-to-your-repo>/java-app
196+
197+
# The following variables will be used for deployment file generation into target.
198+
$Env:LOGIN_SERVER=<Azure-Container-Registry-Login-Server-URL>
199+
$Env:REGISTRY_NAME=<Azure-Container-Registry-name>
200+
$Env:USER_NAME=<Azure-Container-Registry-username>
201+
$Env:PASSWORD=<Azure-Container-Registry-password>
202+
$Env:DB_SERVER_NAME=<server-name>.database.windows.net
203+
$Env:DB_NAME=<database-name>
204+
$Env:DB_USER=<server-admin-login>@<server-name>
205+
$Env:DB_PASSWORD=<server-admin-password>
206+
$Env:INGRESS_TLS_SECRET=<ingress-TLS-secret-name>
207+
208+
mvn clean install
209+
210+
```
211+
212+
---
213+
171214
### (Optional) Test your project locally
172215

173216
You can now run and test the project locally before deploying to Azure. For convenience, we use the `liberty-maven-plugin`. To learn more about the `liberty-maven-plugin`, see [Building a web application with Maven](https://openliberty.io/guides/maven-intro.html). For your application, you can do something similar using any other mechanism, such as your local IDE. You can also consider using the `liberty:devc` option intended for development with containers. You can read more about `liberty:devc` in the [Liberty docs](https://openliberty.io/docs/latest/development-mode.html#_container_support_for_dev_mode).
@@ -199,15 +242,30 @@ You can now use the following steps to test the Docker image locally before depl
199242

200243
1. Run the image using the following command. Note we're using the environment variables defined previously.
201244

245+
### [Bash](#tab/in-bash)
246+
202247
```bash
203248
docker run -it --rm -p 9080:9080 \
204-
-e DB_SERVER_NAME=${DB_SERVER_NAME} \
205-
-e DB_NAME=${DB_NAME} \
206-
-e DB_USER=${DB_USER} \
207-
-e DB_PASSWORD=${DB_PASSWORD} \
208-
javaee-cafe:v1
249+
-e DB_SERVER_NAME=${DB_SERVER_NAME} \
250+
-e DB_NAME=${DB_NAME} \
251+
-e DB_USER=${DB_USER} \
252+
-e DB_PASSWORD=${DB_PASSWORD} \
253+
javaee-cafe:v1
254+
```
255+
256+
### [PowerShell](#tab/in-powershell)
257+
258+
```powershell
259+
docker run -it --rm -p 9080:9080 `
260+
-e DB_SERVER_NAME=${Env:DB_SERVER_NAME} `
261+
-e DB_NAME=${Env:DB_NAME} `
262+
-e DB_USER=${Env:DB_USER} `
263+
-e DB_PASSWORD=${Env:DB_PASSWORD} `
264+
javaee-cafe:v1
209265
```
210266

267+
---
268+
211269
1. Once the container starts, go to `http://localhost:9080/` in your browser to access the application.
212270

213271
1. Press <kbd>Ctrl</kbd>+<kbd>C</kbd> to stop.
@@ -216,15 +274,27 @@ You can now use the following steps to test the Docker image locally before depl
216274

217275
Upload the built image to the ACR created in the offer.
218276

277+
### [Bash](#tab/in-bash)
278+
219279
```bash
220280
docker tag javaee-cafe:v1 ${LOGIN_SERVER}/javaee-cafe:v1
221281
docker login -u ${USER_NAME} -p ${PASSWORD} ${LOGIN_SERVER}
222282
docker push ${LOGIN_SERVER}/javaee-cafe:v1
223283
```
224284

285+
### [PowerShell](#tab/in-powershell)
286+
287+
```powershell
288+
docker tag javaee-cafe:v1 ${Env:LOGIN_SERVER}/javaee-cafe:v1
289+
docker login -u ${Env:USER_NAME} -p ${Env:PASSWORD} ${Env:LOGIN_SERVER}
290+
docker push ${Env:LOGIN_SERVER}/javaee-cafe:v1
291+
```
292+
293+
---
294+
225295
### Deploy and test the application
226296

227-
The following steps deploy and test the application.
297+
Use the following steps to deploy and test the application:
228298

229299
1. Connect to the AKS cluster.
230300

@@ -245,15 +315,13 @@ The following steps deploy and test the application.
245315
kubectl apply -f openlibertyapplication-agic.yaml
246316
```
247317

248-
1. Wait for the pods to be restarted.
249-
250-
Wait until all pods are restarted successfully using the following command.
318+
1. Wait until all pods are restarted successfully by using the following command:
251319

252320
```bash
253321
kubectl get pods --watch
254322
```
255323

256-
You should see output similar to the following to indicate that all the pods are running.
324+
You should see output similar to the following example to indicate that all the pods are running:
257325

258326
```output
259327
NAME READY STATUS RESTARTS AGE
@@ -274,22 +342,44 @@ The following steps deploy and test the application.
274342

275343
1. Go to `https://<ADDRESS>` to test the application. For your convenience, this shell command will create an environment variable whose value you can paste straight into the browser.
276344

345+
### [Bash](#tab/in-bash)
346+
277347
```bash
278348
export APP_URL=https://$(kubectl get ingress | grep javaee-cafe-cluster-agic-ingress | cut -d " " -f14)/
279349
echo $APP_URL
280350
```
281351

352+
### [PowerShell](#tab/in-powershell)
353+
354+
```powershell
355+
$APP_URL = "https://$(kubectl get ingress | Select-String 'javaee-cafe-cluster-agic-ingress' | ForEach-Object { $_.Line.Split(' ')[13] })/"
356+
$APP_URL
357+
```
358+
359+
---
360+
282361
If the web page doesn't render correctly or returns a `502 Bad Gateway` error, that's because the app is still starting in the background. Wait for a few minutes and then try again.
283362
284363
## Clean up resources
285364
286365
To avoid Azure charges, you should clean up unnecessary resources. When the cluster is no longer needed, use the [az group delete](/cli/azure/group#az-group-delete) command to remove the resource group, container service, container registry, and all related resources.
287366
288-
```azurecli-interactive
367+
### [Bash](#tab/in-bash)
368+
369+
```bash
289370
az group delete --name $RESOURCE_GROUP_NAME --yes --no-wait
290371
az group delete --name <db-resource-group> --yes --no-wait
291372
```
292373
374+
### [PowerShell](#tab/in-powershell)
375+
376+
```powershell
377+
az group delete --name $Env:RESOURCE_GROUP_NAME --yes --no-wait
378+
az group delete --name <db-resource-group> --yes --no-wait
379+
```
380+
381+
---
382+
293383
## Next steps
294384
295385
You can learn more from the following references:
-24.1 KB
Loading
Binary file not shown.

0 commit comments

Comments
 (0)