Domain home on a PV
This sample demonstrates how to use the WebLogic Kubernetes Operator (hereafter “the operator”) to set up a WebLogic Server (WLS) cluster on the Azure Kubernetes Service (AKS) using the domain on PV approach. After going through the steps, your WLS domain runs on an AKS cluster and you can manage your WLS domain by accessing the WebLogic Server Administration Console.
Contents
Prerequisites
This sample assumes the following prerequisite environment.
- If you don’t have an
target="_blank” rel=“noopener noreferrer”
Azure subscription , create a
target="_blank” rel=“noopener noreferrer”
free account before you begin.
- It’s strongly recommended that the Azure identity you use to sign in and complete this article has either the
<a href=“ https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#owner"
target="_blank” rel=“noopener noreferrer”
Owner role in the current subscription or the
<a href=“ https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#contributor"
target="_blank” rel=“noopener noreferrer”
Contributor and
target="_blank” rel=“noopener noreferrer”
User Access Administrator roles in the current subscription.
- If your identity has very limited role assignments, ensure you have the following role assignments in the AKS resource group and AKS node resource group.
-
<a href=“ https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#contributor"
target="_blank” rel=“noopener noreferrer”
Contributor role and
target="_blank” rel=“noopener noreferrer”
User Access Administrator role in the resource group that runs AKS cluster. This requires asking a privileged user to assign the roles before creating resource in the resource group.
-
<a href=“ https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles#contributor"
target="_blank” rel=“noopener noreferrer”
Contributor role in the AKS node resource group whose name starts with âMC_â. This requires asking a privileged user to assign the role after the AKS instance is created.
-
- It’s strongly recommended that the Azure identity you use to sign in and complete this article has either the
- Operating System: GNU/Linux, macOS, or
<a href=“ https://learn.microsoft.com/windows/wsl/install"
target="_blank” rel=“noopener noreferrer”
Windows Subsystem for Linux (WSL) .
- Note: the Docker image creation steps will not work on a Mac with Apple Silicon.
-
<a href=“ https://git-scm.com/downloads"
target="_blank” rel=“noopener noreferrer”
Git ; use
git –versionto test ifgitworks. This document was tested with version 2.25.1. -
<a href=“ https://docs.microsoft.com/cli/azure"
target="_blank” rel=“noopener noreferrer”
Azure CLI ; use
az –versionto test ifazworks. This document was tested with version 2.58.0. -
<a href=“ https://www.docker.com/products/docker-desktop"
target="_blank” rel=“noopener noreferrer”
Docker for Desktop . This document was tested with
Docker version 20.10.7. -
<a href=“ https://kubernetes-io-vnext-staging.netlify.com/docs/tasks/tools/install-kubectl/"
target="_blank” rel=“noopener noreferrer”
kubectl ; use
kubectl versionto test ifkubectlworks. This document was tested with version v1.21.2. -
<a href=“ https://helm.sh/docs/intro/install/"
target="_blank” rel=“noopener noreferrer”
Helm , version 3.1 and later; use
helm versionto check thehelmversion. This document was tested with version v3.6.2. - A JDK, version 8 or 11. Azure recommends
<a href=“ https://docs.microsoft.com/java/openjdk/download"
target="_blank” rel=“noopener noreferrer”
Microsoft Build of OpenJDK . Ensure that your
JAVA_HOMEenvironment variable is set correctly in the shells in which you run the commands. - Ensure that you have the zip/unzip utility installed; use
zip/unzip -vto test ifzip/unzipworks. - You will need an Oracle account.
Prepare parameters
Set required parameters by running the following commands.
Oracle Container Registry
The following steps will direct you to accept the license agreement for WebLogic Server. Make note of your Oracle Account password and email. This sample pertains to 12.2.1.4, but other versions may work as well.
- In a web browser, navigate to
<a href=“ https://container-registry.oracle.com ”
target="_blank" rel=“noopener noreferrer”
https://container-registry.oracle.com and log in using the Oracle Single Sign-On authentication service. If you do not already have SSO credentials, at the top of the page, click the Sign In link to create them.
- The Oracle Container Registry provides a WebLogic 12.2.1.4 General Availability (GA) installation image that is used in this sample.
- In the Oracle Container Registry, navigate to Middleware, then weblogic.
- On the left, choose a language and accept the license agreement. You will then see a message such as: “You last accepted the Oracle Standard Terms and Restrictions on 08/10/2020 at 06:12 AM Coordinated Universal Time (UTC).”
- NOTE: General Availability (GA) images are suitable for demonstration and development purposes only where the environments are not available from the public Internet; they are not
acceptable for production use. In production, you should always use CPU (patched) images
from the OCR
or create your images using the
<a href=“ https://oracle.github.io/weblogic-image-tool/userguide/tools/create-image/"
target="_blank” rel=“noopener noreferrer”
WebLogic Image Tool
(WIT) with the
–recommendedPatchesoption. For more guidance, seetarget="_blank” rel=“noopener noreferrer”
Apply the Latest Patches and Updates
in Securing a Production Environment for Oracle WebLogic Server.
- Ensure that Docker is running. Find and pull the WebLogic 12.2.1.4 installation image:
If you have problems accessing the Oracle Container Registry, you can build your own images from the
<a href=“ https://github.com/oracle/docker-images/tree/main/OracleWebLogic/dockerfiles"
target="_blank” rel=“noopener noreferrer”
Oracle GitHub repository .
Sign in with Azure CLI
The steps in this section show you how to sign in to the Azure CLI.
-
Open a Bash shell.
-
Sign out and delete some authentication files to remove any lingering credentials.
-
Sign in to your Azure CLI.
-
Set the subscription ID. Be sure to replace the placeholder with the appropriate value.
Download the WebLogic Kubernetes Operator sample
Download the WebLogic Kubernetes Operator sample ZIP file. We will use several scripts in this zip file to create a WebLogic domain. This sample was tested with v4.2.8, but should work with the latest release.
Info
The following sections of the sample instructions will guide you, step-by-step, through the process of setting up a WebLogic cluster on AKS - remaining as close as possible to a native Kubernetes experience. This lets you understand and customize each step. If you wish to have a more automated experience that abstracts some lower level details, you can skip to the Automation section.
Create Resource Group
Create the resource group by issuing the following commands.
Create the AKS cluster
This sample doesn’t enable application routing. If you want to enable application routing, follow
<a href=“ https://learn.microsoft.com/azure/aks/app-routing?tabs=default%2Cdeploy-app-default"
target="_blank” rel=“noopener noreferrer”
Managed nginx Ingress with the application routing add-on in AKS .
Run the following command to create the AKS cluster.
Successful output will be a JSON object with the entry "type": "Microsoft.ContainerService/ManagedClusters".
After the deployment finishes, run the following command to connect to the AKS cluster. This command updates your local ~/.kube/config so that subsequent kubectl commands interact with the named AKS cluster.
Successful output will look similar to:
After your Kubernetes cluster is up and running, run the following commands to make sure kubectl can access the Kubernetes cluster:
Successful output will look like the following.
NOTE: If you run into VM size failure, see Troubleshooting - Virtual Machine size is not supported .
Create storage
Our usage pattern for the operator involves creating Kubernetes “persistent volumes” to allow the WebLogic Server to persist its configuration and data separately from the Kubernetes Pods that run WebLogic Server workloads.
You will create an external data volume to access and persist data. There are several options for data sharing as described in
<a href=“ https://docs.microsoft.com/azure/aks/concepts-storage"
target="_blank” rel=“noopener noreferrer”
Storage options for applications in Azure Kubernetes Service (AKS) .
You will dynamically create and use a persistent volume with Azure Files NFS share. For details about this full featured cloud storage solution, see the
<a href=“ https://docs.microsoft.com/azure/aks/azure-files-dynamic-pv"
target="_blank” rel=“noopener noreferrer”
Azure Files Documentation .
Create an Azure Storage account and NFS share
-
Create an Azure Storage Account.
Create a storage account using the Azure CLI. Make sure the following values are specified:
Option name Value Notes name$AKS_PERS_STORAGE_ACCOUNT_NAMEThe storage account name can contain only lowercase letters and numbers, and must be between 3 and 24 characters in length. skuPremium_LRSOnly Premium_LRSandPremium_ZRSwork for NFS share, see thetarget="_blank” rel=“noopener noreferrer”
Azure Files NFS Share Documentation .
https-onlyfalseYou canât mount an NFS file share unless you disable secure transfer. default-actionDenyFor security, we suggest that you deny access by default and choose to allow access from the AKS cluster network. Successful output will be a JSON object with the entry
"type": "Microsoft.Storage/storageAccounts". -
Create an NFS share.
We strongly recommend NFS instead of SMB. NFS evolved from the UNIX operating system, and other variants such as GNU/Linux. For this reason, when using NFS with container technologies such as Docker, it is less likely to have problems for concurrent reads and file locking.
Please be sure to enable NFS v4.1. Versions lower than v4.1 will have problems.
To create the file share, you must use
NoRootSquashto allow the operator to change the ownership of the directory in the NFS share.Otherwise, you will get an error like
chown: changing ownership of '/shared': Operation not permitted.The following command creates an NFS share with 100GiB:
The command provisions an NFS file share with NFS 4.1 or above.
-
Assign the AKS cluster Contributor role to access the storage account.
You must configure role assignment allowing access from the AKS cluster to the storage account.
Get the
objectIdof the AKS cluster with the following command and save it with the variableAKS_OBJECT_ID:Get the Id of the storage account with the following command:
Now, you are able to create a role assignment to grant the AKS cluster the Contributor role in the scope of the storage account. Then, the AKS cluster is able to access the file share.
Successful output will be a JSON object like the following:
-
Configure network security.
You must configure network security allowing access from the AKS cluster to the file share.
First, you must get the virtual network name and the subnet name of the AKS cluster.
Run the following commands to get network information:
You must enable the service endpoint
Microsoft.Storagefor the subnet using the following command:It takes several minutes to enable the service endpoint; successful output will be a JSON object like the following:
Now you must create a network rule to allow access from the AKS cluster. The following command enables access from the AKS subnet to the storage account:
Successful output will be a JSON object with a virtual network rule like:
Create SC and PVC
Generated configuration files
Use the following command to generate configuration files.
Use the kubectl command to create the Storage Class and persistent volume claim in the default namespace.
Use the following command to verify:
Example of kubectl get sc output:
Example of kubectl get pvc output:
Create a domain creation image
This sample requires Domain creation images . For more information, see Domain on Persistent Volume .
Image creation prerequisites
-
The
JAVA_HOMEenvironment variable must be set and must reference a valid JDK 8 or 11 installation. -
Copy the sample to a new directory; for example, use the directory
/tmp/dpv-sample. In the directory name,dpvis short for “domain on pv”. Domain on PV is one of three domain home source types supported by the operator. To learn more, see Choose a domain home source type .NOTE: We will refer to this working copy of the sample as
/tmp/dpv-sample; however, you can use a different location. -
Copy the
wdt-artifactsdirectory of the sample to a new directory; for example, use directory/tmp/dpv-sample/wdt-artifacts
-
Download the latest WebLogic Deploying Tooling (WDT) and WebLogic Image Tool (WIT) installer ZIP files to your
${WDT_MODEL_FILES_PATH}directory. Both WDT and WIT are required to create your Model in Image images. -
Set up the WebLogic Image Tool, run the following commands:
These steps will install WIT to the
${WDT_MODEL_FILES_PATH}/imagetooldirectory, plus put awdt_latestentry in the toolâs cache which points to the WDT ZIP file installer. You will use WIT later in the sample for creating model images.
Image creation - Introduction
The goal of image creation is to demonstrate using the WebLogic Image Tool to create an image tagged as wdt-domain-image:WLS-v1 from files that you will stage to ${WDT_MODEL_FILES_PATH}/WLS-v1/.
- The directory where the WebLogic Deploy Tooling software is installed (also known as WDT Home) is expected in an imageâs
/auxiliary/weblogic-deploydirectory. - WDT model YAML (model), WDT variable (property), and WDT archive ZIP (archive) files are expected in directory
/auxiliary/models.
Understanding your first archive
See Understanding your first archive .
Staging a ZIP file of the archive
Delete any possible existing archive.zip in case we have an old leftover version.
Create a ZIP file of the archive in the location that we will use when we run the WebLogic Image Tool.
Staging model files
In this step, you explore the staged WDT model YAML file and properties in the ${WDT_MODEL_FILES_PATH}/WLS-v1 directory. The model in this directory references the web application in your archive, configures a WebLogic Server Administration Server, and configures a WebLogic cluster. It consists of only two files, model.10.properties, a file with a single property, and, model.10.yaml, a YAML file with your WebLogic configuration.
Here is the WLS model.10.properties:
Here is the WLS model.10.yaml:
The model file:
-
Defines a WebLogic domain with:
- Cluster
cluster-1 - Administration Server
admin-server - An EAR application, targeted to
cluster-1, located in the WDT archive ZIP file atwlsdeploy/applications/myapp-v1
- Cluster
-
Leverages macros to inject external values:
- The property file
CLUSTER_SIZEproperty is referenced in the model YAML fileDynamicClusterSizeandMaxDynamicClusterSizefields using a PROP macro. - The model file domain name is injected using a custom environment variable named
CUSTOM_DOMAIN_NAMEusing an ENV macro.- You set this environment variable later in this sample using an
envfield in its Domain. - This conveniently provides a simple way to deploy multiple differently named domains using the same model image.
- You set this environment variable later in this sample using an
- The model file administrator user name and password are set using a
weblogic-credentialssecret macro reference to the WebLogic credential secret.- This secret is in turn referenced using the
webLogicCredentialsSecretfield in the Domain. - The
weblogic-credentialsis a reserved name that always dereferences to the owning Domain actual WebLogic credentials secret name.
- This secret is in turn referenced using the
- The property file
An image can contain multiple properties files, archive ZIP files, and model YAML files but in this sample you use just one of each. For a complete description of WDT model file naming conventions, file loading order, and macro syntax, see Model files in the user documentation.
Creating the image with WIT
At this point, you have all of the files needed for image wdt-domain-image:WLS-v1 staged; they include:
/tmp/sample/wdt-artifacts/wdt-model-files/WLS-v1/model.10.yaml/tmp/sample/wdt-artifacts/wdt-model-files/WLS-v1/model.10.properties/tmp/sample/wdt-artifacts/wdt-model-files/WLS-v1/archive.zip
Now, you use the Image Tool to create an image named wdt-domain-image:WLS-v1. Youâve already set up this tool during the prerequisite steps.
Run the following command to create the image and verify that it worked.
This command runs the WebLogic Image Tool to create the domain creation image and does the following:
- Builds the final container image as a layer on a small
busyboxbase image. - Copies the WDT ZIP file that’s referenced in the WIT cache into the image.
- Note that you cached WDT in WIT using the keyword
latestwhen you set up the cache during the sample prerequisites steps. - This lets WIT implicitly assume it’s the desired WDT version and removes the need to pass a
-wdtVersionflag.
- Note that you cached WDT in WIT using the keyword
- Copies the specified WDT model, properties, and application archives to image location
/auxiliary/models.
When the command succeeds, it should end with output like the following:
Verify the image is available in the local Docker server with the following command.
The output will show something similar to the following:
Note
The imagetool.sh is not supported on macOS with Apple Silicon. See
Troubleshooting - exec format error
.
Note
You may run into a Dockerfile parsing error if your Docker buildkit is enabled, see
Troubleshooting - WebLogic Image Tool failure
.
Pushing the image to Azure Container Registry
AKS can pull images from any container registry, but the easiest integration is to use Azure Container Registry (ACR). In addition to simplicity, using ACR simplifies high availability and disaster recovery with features such as geo-replication. For more information, see
<a href=“ https://learn.microsoft.com/en-us/azure/container-registry/container-registry-geo-replication"
target="_blank” rel=“noopener noreferrer”
Geo-replication in Azure Container Registry . In this section, we will create a new Azure Container Registry, connect it to our pre-existing AKS cluster and push the image built in the preceding section to it. For complete details, see
<a href=“ https://learn.microsoft.com/en-us/azure/container-registry/"
target="_blank” rel=“noopener noreferrer”
Azure Container Registry documentation .
Let’s create an instance of ACR in the same resource group we used for AKS. We will use the environment variables used during the steps above. For simplicity, we use the resource group name as the name of the ACR instance.
Closely examine the JSON output from this command. Save the value of the loginServer property aside. It will look something like the following.
Use this value to sign in to the ACR instance. Note that because you are signing in with the az CLI, you do not need a password because your identity is already conveyed by having done az login previously.
Successful output will include Login Succeeded.
Push the wdt-domain-image:WLS-v1 image created while satisfying the preconditions to this registry.
Finally, connect the AKS cluster to the ACR. For more details on connecting ACR to an existing AKS, see
target="_blank” rel=“noopener noreferrer”
Configure ACR integration for existing AKS clusters .
Successful output will be a JSON object with the entry "type": "Microsoft.ContainerService/ManagedClusters".
If you see an error that seems related to you not being an Owner on this subscription, please refer to the troubleshooting section Cannot attach ACR due to not being Owner of subscription .
Install WebLogic Kubernetes Operator into the AKS cluster
The WebLogic Kubernetes Operator is an adapter to integrate WebLogic Server and Kubernetes, allowing Kubernetes to serve as a container infrastructure hosting WLS instances. The operator runs as a Kubernetes Pod and stands ready to perform actions related to running WLS on Kubernetes.
Kubernetes Operators use
Helm
to manage Kubernetes applications. The operatorâs Helm chart is located in the kubernetes/charts/weblogic-operator directory. Please install the operator by running the corresponding command.
The output will show something similar to the following:
Verify the operator with the following command; the STATUS must be Running. The READY must be 1/1.
Tip
You will have to press Ctrl-C to exit this command due to the -w flag.
Create WebLogic domain
Now that you have created the AKS cluster, installed the operator, and verified that the operator is ready to go, you can ask the operator to create a WLS domain.
Create secrets
You will use the $BASE_DIR/sample-scripts/create-weblogic-domain-credentials/create-weblogic-credentials.sh script to create the domain WebLogic administrator credentials as a Kubernetes secret. Please run the following commands:
The output will show something similar to the following:
You will use the kubernetes/samples/scripts/create-kubernetes-secrets/create-docker-credentials-secret.sh script to create the Docker credentials as a Kubernetes secret. Please run the following commands:
The output will show something similar to the following:
Verify secrets with the following command:
The output will show something similar to the following:
NOTE: If the NAME column in your output is missing any of the values shown above, please review your execution of the preceding steps in this sample to ensure that you correctly followed all of them.
Enable Weblogic Operator
Run the following command to enable the operator to monitor the namespace.
Create WebLogic Domain
Now, you deploy a sample-domain1 domain resource and an associated sample-domain1-cluster-1 cluster resource using a single YAML resource file which defines both resources. The domain resource and cluster resource tells the operator how to deploy a WebLogic domain. They do not replace the traditional WebLogic configuration files, but instead cooperate with those files to describe the Kubernetes artifacts of the corresponding domain.
-
Run the following commands to generate resource files.
Export
Domain_Creation_Image_tag, which will be referred increate-domain-on-aks-generate-yaml.sh.
After running above commands, you will get three files: domain-resource.yaml, admin-lb.yaml, cluster-lb.yaml.
The domain resource references the cluster resource, a WebLogic Server installation image, the secrets you defined, PV and PVC configuration details, and a sample domain creation image, which contains a traditional WebLogic configuration and a WebLogic application. For detailed information, see
Domain and cluster resources
.
-
Run the following command to apply the two sample resources.
-
Create the load balancer services using the following commands:
The output will show something similar to the following:
The output will show something similar to the following:
After a short time, you will see the Administration Server and Managed Servers running.
Use the following command to check server pod status:
It may take you up to 20 minutes to deploy all pods, please wait and make sure everything is ready.
You can tail the logs of the Administration Server with this command:
The final example of pod output is as following:
Tip
If Kubernetes advertises the WebLogic pod as
Runningyou can be assured the WebLogic Server actually is running because the operator ensures that the Kubernetes health checks are actually polling the WebLogic health check mechanism.Get the addresses of the Administration Server and Managed Servers (please wait for the external IP addresses to be assigned):
The final example of service output is as following:
In the example, the URL to access the Administration Server is:
http://4.157.147.131:7001/console. The user name and password that you enter for the Administration Console must match the ones you specified for thedomain1-weblogic-credentialssecret in the Create secrets step.If the WLS Administration Console is still not available, use
kubectl get events --sort-by='.metadata.creationTimestamp'to troubleshoot.
To access the sample application on WLS, skip to the section Access sample application . The next section includes a script that automates all of the preceding steps.
Automation
If you want to automate the above steps of creating the AKS cluster and WLS domain, you can use the script ${BASE_DIR}/sample-scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks.sh.
The sample script will create a WLS domain home on the AKS cluster, including:
- Creating a new Azure resource group, with a new Azure Storage Account and Azure File Share to allow WebLogic to persist its configuration and data separately from the Kubernetes pods that run WLS workloads.
- Creating WLS domain home.
- Generating the domain resource YAML files, which can be used to restart the Kubernetes artifacts of the corresponding domain.
To customize the WLS domain, you can optionally edit ${BASE_DIR}/sample-scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-inputs.sh.
You can now run the script.
The script will take some time to run. The script will print the Administration Server address after a successful deployment.
To interact with the cluster using kubectl, use az aks get-credentials as shown in the script output.
Info
You now have created an AKS cluster with Azure Files NFS share to contain the WLS domain configuration files. Using those artifacts, you have used the operator to create a WLS domain.
Access sample application
Access the Administration Console using the admin load balancer IP address.
Access the sample application using the cluster load balancer IP address.
The test application will list the server host on the output, like the following:
Validate NFS volume
There are several approaches to validate the NFS volume:
- Use Azure Storage browser. Make sure you have permission to access the NFS server, see Azure Storage firewalls and virtual networks document
- Mount the same NFS share in an existing virtual machine from Azure. Access files from the mounted path, see Mount Azure NFS file share to Linux .
Use kubectl exec to enter the admin server pod to check file system status:
You will find output like the following, with filesystem ${AKS_PERS_STORAGE_ACCOUNT_NAME}.file.core.windows.net:/${AKS_PERS_STORAGE_ACCOUNT_NAME}/${AKS_PERS_SHARE_NAME}, size 100G, and mounted on /shared:
Clean up resources
If you used the automation script, the output from the create-domain-on-aks.sh script includes a statement about the Azure resources created by the script. To delete the cluster and free all related resources, simply delete the resource groups. The output will list the resource groups, such as:
Given the above output, the following Azure CLI commands will delete the resource groups.
If you created the AKS cluster step by step, run the following command to clean up resources.
Troubleshooting
For troubleshooting advice, see Troubleshooting .
Useful links
- Domain on a PV sample