From 2f24c6e260ca6325637f753453c1a41f0a38c292 Mon Sep 17 00:00:00 2001 From: Ryan Eberhard Date: Wed, 27 Sep 2023 18:38:11 +0000 Subject: [PATCH] Cherry-pick branch 'update_automation_scripts_and_docs' into 'release/4.1' --- .../content/developerguide/documentation.md | 8 +- .../azure-kubernetes-service/domain-on-pv.md | 344 ++++--- .../includes/clean-up-resources-body-01.txt | 9 +- .../includes/clean-up-resources-body-02.txt | 1 - .../includes/create-aks-cluster-body-02.txt | 12 +- .../includes/create-aks-cluster-storage.txt | 110 +- .../includes/prerequisites-01.txt | 5 +- documentation/site/runlocal.sh | 14 +- .../create-domain-on-aks-generate-yaml.sh | 196 ++++ .../create-domain-on-aks-inputs.sh | 96 ++ .../create-domain-on-aks.sh | 965 +++++++++++------- validateCLI.docker.dat | 5 + 12 files changed, 1165 insertions(+), 600 deletions(-) create mode 100644 kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-generate-yaml.sh create mode 100644 kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-inputs.sh diff --git a/documentation/site/content/developerguide/documentation.md b/documentation/site/content/developerguide/documentation.md index b28f3992228..b5333c13bac 100644 --- a/documentation/site/content/developerguide/documentation.md +++ b/documentation/site/content/developerguide/documentation.md @@ -22,9 +22,9 @@ update to the documentation, follow this process: ``` 3. Make your documentation updates by editing the source files in -`documentation//content`, for example `documentation/4.0/content`. +`documentation/site/content`. {{% notice note %}} -Make sure you check in the changes from the `documentation//content` area _only_; +Make sure you check in the changes from the `documentation/site/content` area _only_; do not build the site and check in the static files. {{% /notice %}} @@ -32,9 +32,11 @@ do not build the site and check in the static files. these commands. The site will be available on the URL shown here: ```shell - $ cd documentation/ + $ cd documentation/site $ hugo server -b http://localhost:1313/weblogic-kubernetes-operator ``` + + You can also run the `runlocal.sh` script in that directory to start the Hugo server locally. 5. When you are ready to submit your changes, push your branch to `origin` and submit a pull request. Remember to follow the guidelines in the diff --git a/documentation/site/content/samples/azure-kubernetes-service/domain-on-pv.md b/documentation/site/content/samples/azure-kubernetes-service/domain-on-pv.md index 27af7770639..72b83ac8981 100644 --- a/documentation/site/content/samples/azure-kubernetes-service/domain-on-pv.md +++ b/documentation/site/content/samples/azure-kubernetes-service/domain-on-pv.md @@ -1,18 +1,27 @@ --- title: "Domain home on a PV" -date: 2020-07-12T18:22:31-05:00 +date: 2023-09-14T18:22:31-05:00 weight: 2 description: "Sample for creating a WebLogic domain home on an existing PV or PVC on the Azure Kubernetes Service." --- -This sample demonstrates how to use the [WebLogic Kubernetes Operator](https://oracle.github.io/weblogic-kubernetes-operator) (hereafter "the operator") to set up a WebLogic Server (WLS) cluster on the Azure Kubernetes Service (AKS) using the model in persistence volume approach. After going through the steps, your WLS domain runs on an AKS cluster instance and you can manage your WLS domain by accessing the WebLogic Server Administration Console. +This sample demonstrates how to use the [WebLogic Kubernetes Operator](https://oracle.github.io/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 instance and you can manage your WLS domain by accessing the WebLogic Server Administration Console. #### Contents - [Prerequisites](#prerequisites) + - [Prepare Parameters](#prepare-parameters) + - [Clone WKO repository](#clone-wko-repository) + - [Create Resource Group](#create-resource-group) - [Create an AKS cluster](#create-the-aks-cluster) + - [Create and Configure Storage](#create-storage) + - [Create an Azure Storage account and NFS share](##create-an-azure-storage-account-and-nfs-share) + - [Create SC and PVC](#create-sc-and-pvc) - [Install WebLogic Kubernetes Operator](#install-weblogic-kubernetes-operator-into-the-aks-cluster) - [Create WebLogic domain](#create-weblogic-domain) + - [Create secrets](#create-secrets) + - [Create WebLogic Domain](#create-weblogic-domain-1) + - [Create LoadBalancer](#create-loadbalancer) - [Automation](#automation) - [Deploy sample application](#deploy-sample-application) - [Validate NFS volume](#validate-nfs-volume) @@ -24,14 +33,6 @@ This sample demonstrates how to use the [WebLogic Kubernetes Operator](https://o {{< readfile file="/samples/azure-kubernetes-service/includes/create-aks-cluster-body-01.txt" >}} -##### Clone WebLogic Kubernetes Operator repository - -Clone the [WebLogic Kubernetes Operator repository](https://github.com/oracle/weblogic-kubernetes-operator) to your machine. You will use several scripts in this repository to create a WebLogic domain. This sample was tested with v3.4.2, but should work with the latest release. - -```shell -$ git clone --branch v{{< latestVersion >}} https://github.com/oracle/weblogic-kubernetes-operator.git -``` - ##### Sign in with Azure CLI The steps in this section show you how to sign in to the Azure CLI. @@ -62,12 +63,109 @@ The steps in this section show you how to sign in to the Azure CLI. {{% notice 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](#automation) section. {{% /notice %}} +#### Prepare parameters + +```shell +# Change these parameters as needed for your own environment +export ORACLE_SSO_EMAIL= +export ORACLE_SSO_PASSWORD= + +# Specify a prefix to name resources, only allow lowercase letters and numbers, between 1 and 7 characters +export BASE_DIR=~ +export NAME_PREFIX=wls +export WEBLOGIC_USERNAME=weblogic +export WEBLOGIC_PASSWORD=Secret123456 +export domainUID=domain1 +# Used to generate resource names. +export TIMESTAMP=`date +%s` +export AKS_CLUSTER_NAME="${NAME_PREFIX}aks${TIMESTAMP}" +export AKS_PERS_RESOURCE_GROUP="${NAME_PREFIX}resourcegroup${TIMESTAMP}" +export AKS_PERS_LOCATION=eastus +export AKS_PERS_STORAGE_ACCOUNT_NAME="${NAME_PREFIX}storage${TIMESTAMP}" +export AKS_PERS_SHARE_NAME="${NAME_PREFIX}-weblogic-${TIMESTAMP}" +export SECRET_NAME_DOCKER="${NAME_PREFIX}regcred" +export ACR_ACCOUNT_NAME="${NAME_PREFIX}acr${TIMESTAMP}" + +``` + +#### Clone WKO repository + +If you have not already done so, clone the [WebLogic Kubernetes Operator repository](https://github.com/oracle/weblogic-kubernetes-operator) to your machine. You will use several scripts in this repository to create a WebLogic domain. This sample was tested with v4.1.1, but should work later releases. + +```shell +$ cd $BASE_DIR +$ git clone https://github.com/oracle/weblogic-kubernetes-operator.git + +``` + +#### Create Resource Group + +```shell +$ cd $BASE_DIR/weblogic-kubernetes-operator +$ az extension add --name resource-graph +$ az group create --name $AKS_PERS_RESOURCE_GROUP --location $AKS_PERS_LOCATION +``` + + {{< readfile file="/samples/azure-kubernetes-service/includes/create-aks-cluster-body-02.txt" >}} **NOTE**: If you run into VM size failure, see [Troubleshooting - Virtual Machine size is not supported]({{< relref "/samples/azure-kubernetes-service/troubleshooting#virtual-machine-size-is-not-supported" >}}). {{< readfile file="/samples/azure-kubernetes-service/includes/create-aks-cluster-storage.txt" >}} +#### Create the Azure Container Registry and connect it to the AKS cluster + +Your AKS cluster must be connected to a container registry so it can pull and interact with container images. The WebLogic Kubernetes Operator assumes that the docker images in the container registry have the correct structure so they are ready to run as WebLogic Docker images. The WebLogic Image Toolkit you used when satisfying the preconditions produces images that meet this requirement. In particular the image `wdt-domain-image:WLS-v1`. The steps in this section show you how to create an Azure Container Registry, connect it to your existing AKS cluster, and push the `wdt-domain-image:WLS-v1` to this registry. + +Create the Azure Container Registry in your existing resource group. + +```shell +az acr create --resource-group $AKS_PERS_RESOURCE_GROUP --name ${ACR_ACCOUNT_NAME} --sku Basic --admin-enabled +``` + +Successful output will be a JSON object that includes the property. + +```json +"id": "/subscriptions//resourceGroups//providers/Microsoft.ContainerRegistry/registries/" +``` + +Obtain the credentials to the Azure Container Registry and perform the `docker login`. + +```shell +export LOGIN_SERVER=$(az acr show \ + --name ${ACR_ACCOUNT_NAME} \ + --query 'loginServer' \ + --output tsv) +export USER_NAME=$(az acr credential show \ + --name ${ACR_ACCOUNT_NAME} \ + --query 'username' \ + --output tsv) +export PASSWORD=$(az acr credential show \ + --name ${ACR_ACCOUNT_NAME} \ + --query 'passwords[0].value' \ + --output tsv) + +docker login $LOGIN_SERVER -u $USER_NAME -p $PASSWORD +``` + +Push the `wdt-domain-image:WLS-v1` image created while satisfying the preconditions to this registry. + +```shell +docker push ${LOGIN_SERVER}/wdt-domain-image:WLS-v1 +``` + +Set an environment variable for use in a later script. + +```shell +# An example of Domain_Creation_Image_tag: xxx.azurecr.io/wdt-domain-image:WLS-v1 +export Domain_Creation_Image_tag=${LOGIN_SERVER}/wdt-domain-image:WLS-v1 +``` + +Connect the Azure Container Registry to your existing AKS cluster. + +```shell +az aks update --name ${AKS_CLUSTER_NAME} --resource-group $AKS_PERS_RESOURCE_GROUP --attach-acr ${ACR_ACCOUNT_NAME} +``` #### Install WebLogic Kubernetes Operator into the AKS cluster @@ -77,8 +175,6 @@ Kubernetes Operators use [Helm](https://helm.sh/) to manage Kubernetes applicati ```shell $ helm repo add weblogic-operator https://oracle.github.io/weblogic-kubernetes-operator/charts --force-update -``` -```shell $ helm install weblogic-operator weblogic-operator/weblogic-operator ``` @@ -114,17 +210,17 @@ weblogic-operator-webhook-868db5875b-55v7r 1/1 Running 0 86s - [Create WebLogic Domain](#create-weblogic-domain-1) - [Create LoadBalancer](#create-loadbalancer) -Now that you have created the AKS cluster, installed the operator, and verified that the operator is ready to go, you can have the operatorto create a WLS 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 `kubernetes/samples/scripts/create-weblogic-domain-credentials/create-weblogic-credentials.sh` script to create the domain WebLogic administrator credentials as a Kubernetes secret. Please run: ``` -# cd kubernetes/samples/scripts/create-weblogic-domain-credentials +cd $BASE_DIR/weblogic-kubernetes-operator/kubernetes/samples/scripts/create-weblogic-domain-credentials ``` ```shell -$ ./create-weblogic-credentials.sh -u -p -d domain1 +$ ./create-weblogic-credentials.sh -u ${WEBLOGIC_USERNAME} -p ${WEBLOGIC_PASSWORD} -d domain1 ``` ``` secret/domain1-weblogic-credentials created @@ -132,24 +228,12 @@ secret/domain1-weblogic-credentials labeled The secret domain1-weblogic-credentials has been successfully created in the default namespace. ``` -Notes: -- Replace `` and `` with a WebLogic administrator username and password of your choice. -- The password should be at least eight characters long and include at least one digit. -- Remember what you specified. These credentials may be needed again later. 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: -```shell -# Please change imagePullSecretNameSuffix if you change pre-defined value "regcred" before generating the configuration files. -``` -```shell -$ export SECRET_NAME_DOCKER="${NAME_PREFIX}regcred" -``` -``` -# cd kubernetes/samples/scripts/create-kubernetes-secrets -``` -```shell -$ ./create-docker-credentials-secret.sh -s ${SECRET_NAME_DOCKER} -e oracleSsoEmail@bar.com -p oracleSsoPassword -u oracleSsoEmail@bar.com +``` shell +$ cd $BASE_DIR/weblogic-kubernetes-operator/kubernetes/samples/scripts/create-kubernetes-secrets +$ ./create-docker-credentials-secret.sh -s ${SECRET_NAME_DOCKER} -e ${ORACLE_SSO_EMAIL} -p ${ORACLE_SSO_PASSWORD} -u ${ORACLE_SSO_EMAIL} ``` ``` secret/wlsregcred created @@ -170,78 +254,46 @@ weblogic-webhook-secrets Opaque 2 wlsregcred kubernetes.io/dockerconfigjson 1 38s ``` -**NOTE**: If the `NAME` column in your output is missing any of the values shown above, please reexamine your execution of the preceding steps in this sample to ensure that you correctly followed all of them. +**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. + +```shell +kubectl label namespace default weblogic-operator=enabled +``` ##### 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. -**NOTE**: Before you deploy the domain custom resource, ensure all nodes in your Kubernetes cluster [can access `domain-creation-image` and other images]({{< relref "/samples/domains/domain-home-on-pv#ensuring-your-kubernetes-cluster-can-access-images" >}}). - -- Copy the contents of the [WLS domain on AKS resource YAML file](https://raw.githubusercontent.com/oracle/weblogic-kubernetes-operator/{{< latestMinorVersion >}}/kubernetes/samples/samples/azure-kubernetes-service/scripts/create-weblogic-domain/domain-on-pv/domain-resources/WLS/domain-on-pv-AKS-v1.yaml) that is included in the sample source to a file called `~/azure/weblogic-on-aks/domain-resource.yaml` or similar. +- Run the following command to generate resource files. -- Run the following command to apply the two sample resources. ```shell - $ kubectl apply -f ~/azure/weblogic-on-aks/domain-resource.yaml + cd $BASE_DIR/weblogic-kubernetes-operator/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service + + bash create-domain-on-aks-generate-yaml.sh ``` - 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]({{< relref "/managing-domains/domain-resource.md" >}}). - -##### Create LoadBalancer - -You must create `LoadBalancer` services for the Administration Server and the WLS cluster. This enables WLS to service requests from outside the AKS cluster. - - Use the sample configuration file `kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/domain-on-pv/admin-lb.yaml` to create a load balancer service for the Administration Server. If you are choosing not to use the predefined YAML file and instead created new one with customized values, then substitute the following content with your domain values. - - ```yaml - apiVersion: v1 - kind: Service - metadata: - name: domain1-admin-server-external-lb - namespace: default - spec: - ports: - - name: default - port: 7001 - protocol: TCP - targetPort: 7001 - selector: - weblogic.domainUID: domain1 - weblogic.serverName: admin-server - sessionAffinity: None - type: LoadBalancer - ``` +After running above commands, you will get three files: `domain-resource.yaml`, `admin-lb.yaml`, `cluster-lb.yaml`. - Use the sample configuration file `kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/domain-on-pv/cluster-lb.yaml` to create a load balancer service for the Managed Servers. If you are choosing not to use the predefined YAML file and instead created new one with customized values, then substitute the following content with your domain values. - - ```yaml - apiVersion: v1 - kind: Service - metadata: - name: domain1-cluster-1-lb - namespace: default - spec: - ports: - - name: default - port: 8001 - protocol: TCP - targetPort: 8001 - selector: - weblogic.domainUID: domain1 - weblogic.clusterName: cluster-1 - sessionAffinity: None - type: LoadBalancer - ``` +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]({{< relref "/managing-domains/domain-resource.md" >}}). + +- Run the following command to apply the two sample resources. + ```shell + $ kubectl apply -f domain-resource.yaml + ``` - Create the load balancer services using the following commands: +- Create the load balancer services using the following commands: ```shell - $ kubectl apply -f ~/azure/weblogic-on-aks/admin-lb.yaml + $ kubectl apply -f admin-lb.yaml ``` ``` service/domain1-admin-server-external-lb created ``` ```shell - $ kubectl apply -f ~/azure/weblogic-on-aks/cluster-lb.yaml + $ kubectl apply -f cluster-lb.yaml ``` ``` service/domain1-cluster-1-external-lb created @@ -266,16 +318,16 @@ You must create `LoadBalancer` services for the Administration Server and the WL The final example of pod output is as following: ```shell - $ kubectl get pods --watch + $ kubectl get pods ``` ``` - NAME READY STATUS RESTARTS AGE - domain1-admin-server 1/1 Running 0 6m34s - domain1-create-weblogic-sample-domain-job-v9hp6 0/1 Completed 0 9m21s - domain1-managed-server1 1/1 Running 0 3m30s - domain1-managed-server2 1/1 Running 0 3m30s - weblogic-operator-69794f8df7-bmvj9 1/1 Running 0 20m - weblogic-operator-webhook-868db5875b-55v7r 1/1 Running 0 20m + NAME READY STATUS RESTARTS AGE + domain1-admin-server 1/1 Running 0 12m + domain1-managed-server1 1/1 Running 0 10m + domain1-managed-server2 1/1 Running 0 10m + weblogic-operator-7796bc7b8-qmhzw 1/1 Running 0 48m + weblogic-operator-webhook-b5b586bc5-ksfg9 1/1 Running 0 48m + ``` {{% notice tip %}} If Kubernetes advertises the WebLogic pod as `Running` you 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. @@ -293,70 +345,26 @@ You must create `LoadBalancer` services for the Administration Server and the WL $ kubectl get svc --watch ``` ``` - NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE - domain1-admin-server ClusterIP None 30012/TCP,7001/TCP 7m51s - domain1-admin-server-ext NodePort 10.0.25.1 7001:30701/TCP 7m51s - domain1-admin-server-external-lb LoadBalancer 10.0.103.99 20.253.86.5 7001:32596/TCP 7m37s - domain1-cluster-1-external-lb LoadBalancer 10.0.95.193 20.253.86.73 8001:32595/TCP 7m22s - domain1-cluster-cluster-1 ClusterIP 10.0.97.134 8001/TCP 4m47s - domain1-managed-server1 ClusterIP None 8001/TCP 4m47s - domain1-managed-server2 ClusterIP None 8001/TCP 4m47s - kubernetes ClusterIP 10.0.0.1 443/TCP 100m - weblogic-operator-webhook-svc ClusterIP 10.0.188.9 8083/TCP,8084/TCP 21m + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + domain1-admin-server ClusterIP None 7001/TCP 13m + domain1-admin-server-external-lb LoadBalancer 10.0.30.252 4.157.147.131 7001:31878/TCP 37m + domain1-cluster-1-lb LoadBalancer 10.0.26.96 4.157.147.212 8001:32318/TCP 37m + domain1-cluster-cluster-1 ClusterIP 10.0.157.174 8001/TCP 10m + domain1-managed-server1 ClusterIP None 8001/TCP 10m + domain1-managed-server2 ClusterIP None 8001/TCP 10m + kubernetes ClusterIP 10.0.0.1 443/TCP 60m + weblogic-operator-webhook-svc ClusterIP 10.0.41.121 8083/TCP,8084/TCP 49m + ``` - In the example, the URL to access the Administration Server is: `http://52.188.176.103:7001/console`. + In the example, the URL to access the Administration Server is: `http://4.157.147.131/console`. The user name and password that you enter for the Administration Console must match the ones you specified for the `domain1-weblogic-credentials` secret in the [Create secrets](#create-secrets) step. - If the WLS Administration Console is still not available, use `kubectl describe domain` to check domain status. + If the WLS Administration Console is still not available, use `kubectl get events --sort-by='.metadata.creationTimestamp' ` to troubleshoot. ```shell - $ kubectl describe domain domain1 - ``` - - Make sure the status of cluster-1 is `ServersReady` and `Available`. - {{%expand "Click here to view the example status." %}} - ```yaml - Status: - Clusters: - Cluster Name: cluster-1 - Maximum Replicas: 5 - Minimum Replicas: 1 - Ready Replicas: 2 - Replicas: 2 - Replicas Goal: 2 - Conditions: - Last Transition Time: 2020-07-06T05:39:32.539Z - Reason: ServersReady - Status: True - Type: Available - Replicas: 2 - Servers: - Desired State: RUNNING - Node Name: aks-nodepool1-11471722-vmss000001 - Server Name: admin-server - State: RUNNING - Cluster Name: cluster-1 - Desired State: RUNNING - Node Name: aks-nodepool1-11471722-vmss000001 - Server Name: managed-server1 - State: RUNNING - Cluster Name: cluster-1 - Desired State: RUNNING - Node Name: aks-nodepool1-11471722-vmss000001 - Server Name: managed-server2 - State: RUNNING - Cluster Name: cluster-1 - Desired State: SHUTDOWN - Server Name: managed-server3 - Cluster Name: cluster-1 - Desired State: SHUTDOWN - Server Name: managed-server4 - Cluster Name: cluster-1 - Desired State: SHUTDOWN - Server Name: managed-server5 + $ kubectl get events --sort-by='.metadata.creationTimestamp' ``` - {{% /expand %}} To deploy a sample application on WLS, you may skip to the section [Deploy sample application](#deploy-sample-application). The next section includes a script that automates all of the preceding steps. @@ -369,31 +377,21 @@ The sample script will create a WLS domain home on the AKS cluster, including: - Creating WLS domain home. - Generating the domain resource YAML files, which can be used to restart the Kubernetes artifacts of the corresponding domain. -For input values, you can edit `kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-inputs.yaml` directly, or copy the file and edit your copy. The following values must be specified: +For input values, you can edit `kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-inputs.sh` directly. The following values must be specified: -| Name in YAML file | Example value | Notes | -|-------------------|---------------|-------| -| `dockerEmail` | `yourDockerEmail` | Oracle Single Sign-On (SSO) account email, used to pull the WebLogic Server Docker image. | -| `dockerPassword` | `yourDockerPassword`| Password for Oracle SSO account, used to pull the WebLogic Server Docker image, in clear text. | -| `dockerUserName` | `yourDockerId` | The same value as `dockerEmail`. | -| `namePrefix` | `wls` | Alphanumeric value used as a disambiguation prefix for several Kubernetes resources. | -| `weblogicUserName` | `` | Enter your choice for a WebLogic administration username. | -| `weblogicAccountPassword` | `` | Enter your choice for a WebLogic administration password. It must be at least eight characters long and contain at least one digit. | - -If you don't want to change the other parameters, you can use the default values. -Please make sure no extra whitespaces are added! -Please also remember the username and password that you chose for the WebLogic administrator account. +| Name in YAML file | Example value | Notes | +|-------------------|---------------------|------------------------------------------------------------------------------------------------| +| `dockerEmail` | `yourDockerEmail` | Oracle Single Sign-On (SSO) account email, used to pull the WebLogic Server Docker image. | +| `dockerPassword` | `yourDockerPassword` | Password for Oracle SSO account, used to pull the WebLogic Server Docker image, in clear text. | +| `weblogicUserName` | `weblogic` | Uername for WebLogic user account. | +| `weblogicAccountPassword` | `Secret123456` | Password for WebLogic user account. | ``` -# Use ~/azure as output directory, please change it according to your requirement. - -# cd kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service -``` -```shell -$ cp create-domain-on-aks-inputs.yaml my-create-domain-on-aks-inputs.yaml +cd kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service ``` + ```shell -$ ./create-domain-on-aks.sh -i my-create-domain-on-aks-inputs.yaml -o ~/azure -e +$ ./create-domain-on-aks.sh ``` The script will print the Administration Server address after a successful deployment. @@ -409,7 +407,7 @@ Now that you have WLS running in AKS, you can test the cluster by deploying the First, package the application with the following command: ```bash -cd integration-tests/src/test/resources/bash-scripts +cd $BASE_DIR/weblogic-kubernetes-operator/integration-tests/src/test/resources/bash-scripts bash build-war-app.sh -s ../apps/testwebapp/ -d /tmp/testwebapp ``` @@ -434,11 +432,11 @@ adding: index.jsp(in = 1001) (out= 459)(deflated 54%) ``` Now, you are able to deploy the sample application in `/tmp/testwebapp/testwebapp.war` to the cluster. This sample uses WLS RESTful API [/management/weblogic/latest/edit/appDeployments](https://docs.oracle.com/en/middleware/standalone/weblogic-server/14.1.1.0/wlrer/op-management-weblogic-version-edit-appdeployments-x-operations-1.html) to deploy the sample application. -Replace `` and `` with the values you specified in [Create secrets](#create-secrets) or [Automation](#automation): +Replace `${WEBLOGIC_USERNAME}` and `${WEBLOGIC_PASSWORD}` with the values you specified in [Create secrets](#create-secrets) or [Automation](#automation): ```bash $ ADMIN_SERVER_IP=$(kubectl get svc domain1-admin-server-external-lb -o=jsonpath='{.status.loadBalancer.ingress[0].ip}') -$ curl --user : -H X-Requested-By:MyClient -H Accept:application/json -s -v \ +$ curl --user ${WEBLOGIC_USERNAME}:${WEBLOGIC_PASSWORD} -H X-Requested-By:MyClient -H Accept:application/json -s -v \ -H Content-Type:multipart/form-data \ -F "model={ name: 'testwebapp', diff --git a/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-01.txt b/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-01.txt index 9bbdd9c7c8d..1253deb30a6 100644 --- a/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-01.txt +++ b/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-01.txt @@ -1,13 +1,12 @@ 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. ```shell -The following Azure resources have been created: - Resource groups: ejb8191resourcegroup1597641911, MC_ejb8191resourcegroup1597641911_ejb8191akscluster1597641911_eastus +The following Azure Resouces have been created: + Resource groups: wlsresourcegroup6091605169, MC_wlsresourcegroup6091605169_wlsakscluster6091605169_eastus ``` Given the above output, the following Azure CLI commands will delete the resource groups. ```shell -$ az group delete --yes --no-wait --name ejb8191resourcegroup1597641911 -$ az group delete --yes --no-wait --name MC_ejb8191resourcegroup1597641911_ejb8191akscluster1597641911_eastus -``` \ No newline at end of file +$ az group delete --yes --no-wait --name wlsresourcegroup6091605169 +``` diff --git a/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-02.txt b/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-02.txt index 58692bd0318..35c35b9113f 100644 --- a/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-02.txt +++ b/documentation/site/content/samples/azure-kubernetes-service/includes/clean-up-resources-body-02.txt @@ -1,5 +1,4 @@ ```shell $ az group delete --yes --no-wait --name $AKS_PERS_RESOURCE_GROUP -$ az group delete --yes --no-wait --name "MC_$AKS_PERS_RESOURCE_GROUP"_"$AKS_CLUSTER_NAME"_"$AKS_PERS_LOCATION" ``` diff --git a/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-body-02.txt b/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-body-02.txt index 8107dd93bc5..f4a997a578e 100644 --- a/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-body-02.txt +++ b/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-body-02.txt @@ -1,3 +1,4 @@ + #### Create the AKS cluster This sample requires that you disable the AKS addon `http_application_routing` by default. If you want to enable `http_application_routing`, then follow [HTTP application routing](https://docs.microsoft.com/azure/aks/http-application-routing). @@ -5,16 +6,7 @@ This sample requires that you disable the AKS addon `http_application_routing` b Run the following commands to create the AKS cluster instance. ```shell -# Change these parameters as needed for your own environment -# Specify a prefix to name resources, only allow lowercase letters and numbers, between 1 and 7 characters -$ export NAME_PREFIX=wls -# Used to generate resource names. -$ export TIMESTAMP=`date +%s` -$ export AKS_CLUSTER_NAME="${NAME_PREFIX}aks${TIMESTAMP}" -$ export AKS_PERS_RESOURCE_GROUP="${NAME_PREFIX}resourcegroup${TIMESTAMP}" -$ export AKS_PERS_LOCATION=eastus - -$ az group create --name $AKS_PERS_RESOURCE_GROUP --location $AKS_PERS_LOCATION + $ az aks create \ --resource-group $AKS_PERS_RESOURCE_GROUP \ --name $AKS_CLUSTER_NAME \ diff --git a/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-storage.txt b/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-storage.txt index 9048c0dbcb3..e122c759d3d 100644 --- a/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-storage.txt +++ b/documentation/site/content/samples/azure-kubernetes-service/includes/create-aks-cluster-storage.txt @@ -20,8 +20,6 @@ You will dynamically create and use a persistent volume with Azure Files NFS sha | `default-action` | `Deny` | For security, we suggest that you deny access by default and choose to allow access from the AKS cluster network. | ```shell - # Change the value as needed for your own environment - $ export AKS_PERS_STORAGE_ACCOUNT_NAME="${NAME_PREFIX}storage${TIMESTAMP}" $ az storage account create \ --resource-group $AKS_PERS_RESOURCE_GROUP \ @@ -44,8 +42,7 @@ You will dynamically create and use a persistent volume with Azure Files NFS sha The following command creates an NFS share with 100GiB: ```shell - # Change value as needed for your own environment - $ export AKS_PERS_SHARE_NAME="${NAME_PREFIX}-weblogic-${TIMESTAMP}" + # Create NFS file share $ az storage share-rm create \ --resource-group $AKS_PERS_RESOURCE_GROUP \ @@ -184,74 +181,53 @@ You will dynamically create and use a persistent volume with Azure Files NFS sha ] ``` -##### Create Storage Class +##### Create SC and PVC -This sample will dynamically create and use a persistent volume with Azure Files in AKS. These features are passed to Kubernetes using YAML files. - -The script `kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks.sh` generates the required configuration files automatically, given an input file containing the parameters. - -A parameters file is provided at `kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-inputs.yaml`. Copy and customize this file for your needs. - -To generate YAML files to create Storage Class in the AKS cluster, the following values must be substituted in your copy of the input file. - -| Name in YAML file | Example value | Notes | -|-------------------|---------------|-------| -| `namePrefix` | `wls` | Alphanumeric value used as a disambiguation prefix for several Kubernetes resources. Make sure the value matches the value of `${NAME_PREFIX}` to keep names in step-by-step commands the same with those in configuration files. | - -Use the following command to generate configuration files, assuming the output directory is `~/azure`. The script will overwrite any files generated by a previous invocation. - -```shell -$ cd kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service -$ cp create-domain-on-aks-inputs.yaml my-create-domain-on-aks-inputs.yaml -$ ./create-domain-on-aks.sh -i my-create-domain-on-aks-inputs.yaml -o ~/azure -u ${TIMESTAMP} -``` - -After running the command, all needed configuration files are generated and output to `~/azure/weblogic-on-aks`: +##### Generated configuration files +Use the below command to generate configuration files. ```shell -The following files were generated: - /home/username/azure/weblogic-on-aks/azure-csi-nfs.yaml - /home/username/azure/weblogic-on-aks/pvc.yaml - /home/username/azure/weblogic-on-aks/admin-lb.yaml - /home/username/azure/weblogic-on-aks/cluster-lb.yaml - /home/username/azure/weblogic-on-aks/domain1.yaml - -Completed -``` - -**NOTE**: Beyond the required and default configurations generated by the command, you can modify the generated YAML files to further customize your deployment. For further information about customizing your deployment, consult the operator documentation, [AKS documentation](https://docs.microsoft.com/azure/aks/), and Kubernetes references. - -##### Apply generated configuration files +cat >azure-csi-nfs-${TIMESTAMP}.yaml <pvc-${TIMESTAMP}.yaml <}}) step. \ No newline at end of file +* A `domain creation image` tagged as `wdt-domain-image:WLS-v1` in your local Docker server's image cache. You can create it by following the [Build the domain creation image]({{< relref "/samples/domains/domain-home-on-pv/build-domain-creation-image#build-the-domain-creation-image" >}}) step. diff --git a/documentation/site/runlocal.sh b/documentation/site/runlocal.sh index a73b68f0888..9f2a604f5da 100755 --- a/documentation/site/runlocal.sh +++ b/documentation/site/runlocal.sh @@ -3,7 +3,19 @@ # Copyright (c) 2019, 2021, Oracle and/or its affiliates. # Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +# `./runlocal.sh ` causes the +# site to be available at `http://:/weblogic-kubernetes-operator/`. This is useful when running on +# a LAN. `./runlocal.sh` with no arguments continues to operate as +# originally writen. That is, the site is available at +# http://localhost:1313/weblogic-kubernetes-operator/. + # 1313 is the hugo default port port=${1:-1313} +host=${2-localhost} + +if [[ $host != 'localhost'* ]]; then + bind="--bind $host" +fi -hugo server -b http://localhost:$port/weblogic-kubernetes-operator -D -p $port +hugo server $bind --baseURL http://$host:$port/weblogic-kubernetes-operator --buildDrafts -p $port diff --git a/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-generate-yaml.sh b/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-generate-yaml.sh new file mode 100644 index 00000000000..af41117a8a4 --- /dev/null +++ b/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks-generate-yaml.sh @@ -0,0 +1,196 @@ +cat >domain-resource.yaml <admin-lb.yaml <cluster-lb.yaml <, e.g. wlsresourcegroup1592469388 +# Kubernetes cluster is named with ${namePrefix}akscluster, e.g. wlsakscluster1592469388 +# Storage account is named with ${namePrefix}storage, e.g. wlsstorage1592469388 +export namePrefix=wls + +# +# Parameters that may optionally be changed. +# + +# The suffix of file share secret name, the complete value is ${namePrefix}${azureFileShareSecretNameSuffix}. +export azureFileShareSecretNameSuffix=azure-secret + +# Number of azure kubernetes nodes, used to create azure kubernetes cluster. +export azureKubernetesNodeCount=2 + +# VM size of azure kubernetes node. +export azureKubernetesNodeVMSize=Standard_DS2_v2 + +# The suffix of azure kubernetes node pool name, the azure kubernetes node pool name will be${azureKubernetesNodepoolNamePrefix} ${namePrefix}. +export azureKubernetesNodepoolNamePrefix=pool1 + +#Java Option for WebLogic Server +export javaOptions="-Dweblogic.StdoutDebugEnabled=false -XX:InitialRAMPercentage=25.0 -XX:MaxRAMPercentage=50.0" + +# The suffix of the Kubernetes secret name, the complete value is ${namePrefix}${imagePullSecretNameSuffix}. The secret name is used to access the container registry to pull the WebLogic Server image +# Used to create Kubernetes secret for container registry account. +# Parameter "imagePullSecretName" will be overwritten with this field in kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-inputs.yaml +export imagePullSecretNameSuffix=regcred + +# Storage class name for Azure Files using Container Storage Interface driver, see https://docs.microsoft.com/en-us/azure/aks/azure-files-csi#nfs-file-shares +export azureFileCsiNfsClassName=azurefile-csi-nfs + +# The suffix of azure storage file share name, the complete value is ${namePrefix}-${azureStorageShareNameSuffix}-, used to create file share, and mount file share. +export azureStorageShareNameSuffix=weblogic + +# Resource request for each server pod (Memory and CPU). This is minimum amount of compute +# resources required for each server pod. Edit value(s) below as per pod sizing requirements. +# These are optional +# Please refer to the kubernetes documentation on Managing Compute +# Resources for Containers for details. +# Parameter "serverPodMemoryRequest" and "serverPodCpuRequest" will be overwritten with this field in kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-inputs.yaml +export serverPodMemoryRequest="1.5Gi" +export serverPodCpuRequest="250m" + +# Uncomment and edit value(s) below to specify the maximum amount of compute resources allowed +# for each server pod. +# These are optional. +# Please refer to the kubernetes documentation on Managing Compute +# Resources for Containers for details. +# Parameter "serverPodMemoryLimit" and "serverPodCpuLimit" will be overwritten with this field in kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-inputs.yaml +export serverPodMemoryLimit="1.5Gi" +export serverPodCpuLimit="250m" + +# The suffix of the persistent volume claim name, the complete value is ${namePrefix}-${persistentVolumeClaimNameSuffix}-. +# Parameter "persistentVolumeClaimName" will be overwritten with this field in kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-inputs.yaml +export persistentVolumeClaimNameSuffix=azurefile + +# WebLogic Server image. +# Parameter "image" will be overwritten with this field in kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-inputs.yaml +# **NOTE**: +# This sample uses General Availability (GA) images. 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 OCR or create your images using the WebLogic Image Tool. +# Please refer to the `OCR` and `WebLogic Images` pages in the WebLogic Kubernetes Operator +# documentation for details. +export weblogicDockerImage=container-registry.oracle.com/middleware/weblogic:12.2.1.4 + + + diff --git a/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks.sh b/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks.sh index dce23308c71..fc68d04f6e1 100755 --- a/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks.sh +++ b/kubernetes/samples/scripts/create-weblogic-domain-on-azure-kubernetes-service/create-domain-on-aks.sh @@ -26,63 +26,9 @@ script="${BASH_SOURCE[0]}" scriptDir="$(cd "$(dirname "${script}")" && pwd)" -source ${scriptDir}/../common/utility.sh -source ${scriptDir}/../common/validate.sh - -usage() { - echo usage: ${script} -i file -o dir [-u uid] [-e] [-d] [-h] - echo " -i Parameter inputs file, must be specified." - echo " -o Output directory for the generated yaml files, must be specified." - echo " -u UID of resource, used to name file share, persistent valume, and persistent valume claim. " - echo " -e Also create the Azure Kubernetes Service and create WebLogic Server domain on it using the generated yaml files" - echo " -d Paramters inputs file for creating domain, you can use specifed configuration by changing values of kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/create-domain-inputs.yaml, otherwise, we will use that file by default." - echo " -h Help" - exit $1 -} - -# -# Parse the command line options -# -executeIt=false -while getopts "ehi:o:u:d:" opt; do - case $opt in - i) - valuesInputFile="${OPTARG}" - ;; - o) - outputDir="${OPTARG}" - ;; - u) - azureResourceUID="${OPTARG}" - ;; - e) - executeIt=true - ;; - d) - domainInputFile="${OPTARG}" - ;; - h) - usage 0 - ;; - *) - usage 1 - ;; - esac -done - -if [ -z ${valuesInputFile} ]; then - echo "${script}: -i must be specified." - missingRequiredOption="true" -fi - -if [ -z ${outputDir} ]; then - echo "${script}: -o must be specified." - missingRequiredOption="true" -fi - -if [ "${missingRequiredOption}" == "true" ]; then - usage 1 -fi +#Kubernetes command line interface. +#Default is 'kubectl' if KUBERNETES_CLI env variable is not set. +kubernetesCli=${KUBERNETES_CLI:-kubectl} if [ -z "${azureResourceUID}" ]; then azureResourceUID=$(date +%s) @@ -96,182 +42,190 @@ fail() { exit 1 } -# -# Function to initialize and validate the output directory -# for the generated yaml files for this domain. -# -initOutputDir() { - aksOutputDir="$outputDir/weblogic-on-aks" - - scOutput="${aksOutputDir}/azure-csi-nfs.yaml" - pvcOutput="${aksOutputDir}/pvc.yaml" - adminLbOutput="${aksOutputDir}/admin-lb.yaml" - clusterLbOutput="${aksOutputDir}/cluster-lb.yaml" - domain1Output="${aksOutputDir}/domain1.yaml" - - removeFileIfExists ${scOutput} - removeFileIfExists ${pvcOutput} - removeFileIfExists ${adminLbOutput} - removeFileIfExists ${clusterLbOutput} - removeFileIfExists ${domain1Output} - removeFileIfExists ${aksOutputDir}/create-domain-on-aks-inputs.yaml +# Define display end------------- +BLUE="\033[34m" +RED="\033[31m" +RESET="\033[0m" + +# Function: Print colored message +print_message() { + local contenxt="$1" + local color="$2" + + echo -e "${color} ${contenxt}${RESET}" } -# -# Function to setup the environment to run the create Azure resource and domain job -# -initialize() { +print_blue() { + local contenxt="$1" + echo -e "${BLUE} ${contenxt}${RESET}" +} - # Validate the required files exist - validateErrors=false +print_red() { + local contenxt="$1" + echo -e "${RED} ${contenxt}${RESET}" +} - if [ -z "${valuesInputFile}" ]; then - validationError "You must use the -i option to specify the name of the inputs parameter file (a modified copy of kubernetes/samples/scripts/create-weblogic-domain-on-aks/create-domain-on-aks-inputs.yaml)." +steps=0 +total_steps=11 +print_step { + ((steps++)) + print_blue "Progress $steps/$total_steps.......... $1" +} +# +# Function to validate the host environment meets the prerequisites. +# $1 - text of message +envValidate() { + print_step "Checking host environment" + # Check if the user is logged in to Azure CLI + if az account show >/dev/null 2>&1; then + print_blue "Logged in to Azure CLI" else - if [ ! -f ${valuesInputFile} ]; then - validationError "Unable to locate the input parameters file ${valuesInputFile}" - fi + print_red "[ERROR]Not logged in to Azure CLI. Please log in." + exit 1 fi - if [ -z "${outputDir}" ]; then - validationError "You must use the -o option to specify the name of an existing directory to store the generated yaml files in." + # Check if Java JDK is installed + java_version=$(java -version 2>&1) + + # "Checking if Java is installed..." + if type -p java; then + print_blue "Java JDK is installed. Version:" + java -version + else + print_red "[ERROR]Java JDK is not installed. Please install Java JDK." + exit 1 fi - storageClassInput="${scriptDir}/azure-csi-storageaccount-template.yaml" - if [ ! -f ${storageClassInput} ]; then - validationError "The template file ${storageClassInput} for generating a NFS storage class was not found" + # Check if Docker is installed + if command -v docker &> /dev/null; then + echo "Docker is installed." + else + print_red "[ERROR]Docker is not installed. Please install Docker." + exit 1 fi - domainPVCInput="${scriptDir}/azure-file-pvc-template.yaml" - if [ ! -f ${domainPVCInput} ]; then - validationError "The template file ${domainPVCInput} for generating a persistent volume claim was not found" + # Check if Helm is installed + if command -v helm &> /dev/null; then + print_blue "Helm is installed." + else + print_red "[ERROR]Helm is not installed. Please install Helm." + exit 1 fi - wlsLbInput="${scriptDir}/loadbalancer-template.yaml" - if [ ! -f ${wlsLbInput} ]; then - validationError "The template file ${wlsLbInput} for generating load balancer for Administration Server was not found" + # Check if kubectl is installed + if command -v ${kubernetesCli} &> /dev/null; then + print_blue "${kubernetesCli} is installed." + else + print_red "[ERROR]${kubernetesCli} is not installed. Please install ${kubernetesCli}." + exit 1 fi - failIfValidationErrors + echo "Checking host environment passed." +} - # Parse the common inputs file - parseCommonInputs - initOutputDir - failIfValidationErrors +parametersValidate() { + print_step "validating parameters" + + # Get the values of environment variables + email="$dockerEmail" + password="$dockerPassword" + + while getopts "u:p:" option; do + case "${option}" in + u) + email=${OPTARG} + ;; + p) + password=${OPTARG} + ;; + esac + done - if [ ${#namePrefix} -gt 7 ]; then - fail "namePrefix is allowed lowercase letters and numbers, between 1 and 7 characters." + # Check for default values and prompt for setting + if [ "$email" = "docker-email" ]; then + echo -n "Please enter a value for 'dockerEmail'(Oracle Single Sign-On (SSO) account email): " + read input_email + if [ -z "$input_email" ]; then + echo "No value provided for 'dockerEmail'. Please set the value and rerun the script." + exit 1 + fi + email="$input_email" fi - # Generate Azure resource name - export azureResourceGroupName="${namePrefix}resourcegroup${azureResourceUID}" - export aksClusterName="${namePrefix}akscluster${azureResourceUID}" - export storageAccountName="${namePrefix}storage${azureResourceUID}" + if [ "$password" = "docker-password" ]; then + echo -n "Please enter a value for 'dockerPassword'(Oracle Single Sign-On (SSO) account password): " + read -s input_password + echo + if [ -z "$input_password" ]; then + echo "No value provided for 'dockerPassword'. Please set the value and rerun the script." + exit 1 + fi + password="$input_password" + fi + + # Export the updated values of environment variables + export dockerEmail="$email" + export dockerPassword="$password" + + + # Attempt to login to Docker + sudo chmod 666 /var/run/docker.sock + docker login container-registry.oracle.com -u "$dockerEmail" -p "$dockerPassword" > /dev/null 2>&1 + + # Check the login result + if [ $? -eq 0 ]; then + echo "Oracle Single Sign-On (SSO) account Username and password are correct" + # Logout from Docker + docker logout > /dev/null 2>&1 + else + print_red "[ERROR]Invalid Oracle Single Sign-On (SSO) account username or password." + exit 1 + fi - export azureFileShareSecretName="${namePrefix}${azureFileShareSecretNameSuffix}" - export azureKubernetesNodepoolName="${azureKubernetesNodepoolNamePrefix}${namePrefix}" - export azureStorageShareName="${namePrefix}-${azureStorageShareNameSuffix}-${azureResourceUID}" - export imagePullSecretName="${namePrefix}${imagePullSecretNameSuffix}" - export persistentVolumeClaimName="${namePrefix}-${persistentVolumeClaimNameSuffix}-${azureResourceUID}" - export persistentVolumeId="${namePrefix}-${persistentVolumeClaimNameSuffix}-${azureResourceUID}" } + # -# Function to generate the yaml files for creating Azure resources and WebLogic Server domain +# Function to setup the environment to run the create Azure resource and domain job # -createYamlFiles() { - - # Create a directory for this domain's output files - mkdir -p ${aksOutputDir} - - # Make sure the output directory has a copy of the inputs file. - # The user can either pre-create the output directory, put the inputs - # file there, and create the domain from it, or the user can put the - # inputs file some place else and let this script create the output directory - # (if needed) and copy the inputs file there. - copyInputsFileToOutputDirectory ${valuesInputFile} "${aksOutputDir}/create-domain-on-aks-inputs.yaml" +initialize() { - echo Generating ${scOutput} + print_step "initializing" + source ./create-domain-on-aks-inputs.sh + source ~/.bashrc + + # Generate Azure resource name - cp ${storageClassInput} ${scOutput} - sed -i -e "s:%STORAGE_CLASS_NAME%:${azureFileCsiNfsClassName}:g" ${scOutput} - sed -i -e "s:%AZURE_FILE_SHARE_NAME%:${azureStorageShareName}:g" ${scOutput} - sed -i -e "s:%STORAGE_ACCOUNT_RESOURCE_GROUP_NAME%:${azureResourceGroupName}:g" ${scOutput} - sed -i -e "s:%STORAGE_ACCOUNT_NAME%:${storageAccountName}:g" ${scOutput} + export image_build_branch_name="v4.1.1" + export image_build_base_dir="/tmp/tmp${azureResourceUID}" - # Generate the yaml to create the persistent volume claim - echo Generating ${pvcOutput} + export acr_account_name=${namePrefix}acr${azureResourceUID} + export docker_secret_name="${namePrefix}regcred" - cp ${domainPVCInput} ${pvcOutput} - sed -i -e "s:%PERSISTENT_VOLUME_CLAIM_NAME%:${persistentVolumeClaimName}:g" ${pvcOutput} - sed -i -e "s:%STORAGE_CLASS_NAME%:${azureFileCsiNfsClassName}:g" ${pvcOutput} + export azureResourceGroupName="${namePrefix}resourcegroup${azureResourceUID}" + export aksClusterName="${namePrefix}akscluster${azureResourceUID}" + export storageAccountName="${namePrefix}storage${azureResourceUID}" - # Generate the yaml to create WebLogic Server domain. - echo Generating ${domain1Output} + export azureKubernetesNodepoolName="${azureKubernetesNodepoolNamePrefix}${namePrefix}" + export azureStorageShareName="${namePrefix}-${azureStorageShareNameSuffix}-${azureResourceUID}" + export domainUID="domain1" - if [ -z ${domainInputFile} ]; then - domainInputFile="${dirCreateDomain}/create-domain-inputs.yaml" - fi - cp ${domainInputFile} ${domain1Output} - sed -i -e "s;^image\:.*;image\: ${weblogicDockerImage};g" ${domain1Output} - sed -i -e "s:#imagePullSecretName.*:imagePullSecretName\: ${imagePullSecretName}:g" ${domain1Output} - sed -i -e "s:imagePullSecretName.*:imagePullSecretName\: ${imagePullSecretName}:g" ${domain1Output} - sed -i -e "s:exposeAdminNodePort.*:exposeAdminNodePort\: true:g" ${domain1Output} - sed -i -e "s:persistentVolumeClaimName.*:persistentVolumeClaimName\: ${persistentVolumeClaimName}:g" ${domain1Output} - sed -i -e "s:serverPodMemoryRequest.*:serverPodMemoryRequest\: ${serverPodMemoryRequest}:g" ${domain1Output} - sed -i -e "s:serverPodCpuRequest.*:serverPodCpuRequest\: ${serverPodCpuRequest}:g" ${domain1Output} - sed -i -e "s:serverPodMemoryLimit.*:serverPodMemoryLimit\: ${serverPodMemoryLimit}:g" ${domain1Output} - sed -i -e "s:serverPodCpuLimit.*:serverPodCpuLimit\: ${serverPodCpuLimit}:g" ${domain1Output} - sed -i -e "s;^javaOptions.*;javaOptions\: \"${javaOptions}\";g" ${domain1Output} - - # Parse domain configuration yaml for usage in load balancer - exportValuesFile=$(mktemp /tmp/export-values-XXXXXXXXX.sh) - tmpFile=$(mktemp /tmp/javaoptions_tmp-XXXXXXXXX.dat) - parseYaml ${domain1Output} ${exportValuesFile} - if [ ! -f ${exportValuesFile} ]; then - echo Unable to locate the parsed output of ${domain1Output}. - fail 'The file ${exportValuesFile} could not be found.' - fi + echo "image_build_branch_name=${image_build_branch_name}" + echo "aksClusterName=${aksClusterName}" + echo "storageAccountName=${storageAccountName}" - # Define the environment variables that will be used to fill in template values - echo Domain parameters being used - cat ${exportValuesFile} - echo - # javaOptions may contain tokens that are not allowed in export command - # we need to handle it differently. - # we set the javaOptions variable that can be used later - tmpStr=$(grep "javaOptions" ${exportValuesFile}) - javaOptions=${tmpStr//"javaOptions="/} - - # We exclude javaOptions from the exportValuesFile - grep -v "javaOptions" ${exportValuesFile} >${tmpFile} - source ${tmpFile} - rm ${exportValuesFile} ${tmpFile} - - # Generate the yaml to create load balancer for Administration Server. - echo Generating ${adminLbOutput} - - cp ${wlsLbInput} ${adminLbOutput} - sed -i -e "s:%SELECTOR_SERVER_TYPE%:${selectorAdminServerName}:g" ${adminLbOutput} - sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${adminLbOutput} - sed -i -e "s:%SERVER_PORT%:${adminPort}:g" ${adminLbOutput} - sed -i -e "s:%SERVER_NAME%:${adminServerName}:g" ${adminLbOutput} - - # Generate the yaml to create load balancer for WebLogic Server cluster. - echo Generating ${clusterLbOutput} - - cp ${wlsLbInput} ${clusterLbOutput} - sed -i -e "s:%SELECTOR_SERVER_TYPE%:${selectorClusterServerName}:g" ${clusterLbOutput} - sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${clusterLbOutput} - sed -i -e "s:%SERVER_PORT%:${managedServerPort}:g" ${clusterLbOutput} - sed -i -e "s:%SERVER_NAME%:${clusterName}:g" ${clusterLbOutput} - - # Remove any "...yaml-e" files left over from running sed - rm -f ${aksOutputDir}/*.yaml-e + echo "azureResourceGroupName=${azureResourceGroupName}" + echo "image_build_base_dir=${image_build_base_dir}" + echo "acr_account_name=${acr_account_name}" + + } + createResourceGroup() { + print_step "createing resourcegroup" + az extension add --name resource-graph # Create a resource group @@ -286,6 +240,9 @@ createResourceGroup() { } createAndConnectToAKSCluster() { + + print_step "creating AKS" + # Create aks cluster echo Check if ${aksClusterName} exists ret=$(az aks list -g ${azureResourceGroupName} | grep "${aksClusterName}") @@ -294,15 +251,42 @@ createAndConnectToAKSCluster() { fi echo Creating Azure Kubernetes Service ${aksClusterName} - az aks create --resource-group $azureResourceGroupName \ - --name $aksClusterName \ - --vm-set-type VirtualMachineScaleSets \ - --node-count ${azureKubernetesNodeCount} \ - --generate-ssh-keys \ - --nodepool-name ${azureKubernetesNodepoolName} \ - --node-vm-size ${azureKubernetesNodeVMSize} \ - --location $azureLocation \ - --enable-managed-identity + + # Create AKS command + create_command="az aks create --resource-group $azureResourceGroupName \ + --name $aksClusterName \ + --vm-set-type VirtualMachineScaleSets \ + --node-count ${azureKubernetesNodeCount} \ + --generate-ssh-keys \ + --nodepool-name ${azureKubernetesNodepoolName} \ + --node-vm-size ${azureKubernetesNodeVMSize} \ + --location $azureLocation \ + --enable-managed-identity" + + # Maximum number of retries + max_retries=3 + retry_count=0 + + while true; do + # Execute create AKS command + $create_command + + # Check exit status + if [ $? -eq 0 ]; then + echo "AKS creation successful" + break + else + retry_count=$((retry_count+1)) + if [ $retry_count -le $max_retries ]; then + echo "AKS creation failed. Retrying attempt $retry_count..." + # Delete previously created AKS + az aks delete --resource-group $azureResourceGroupName --name $aksClusterName --yes --no-wait + else + echo "Maximum retry limit reached. Unable to create AKS" + exit 1 + fi + fi + done # Connect to AKS cluster echo Connencting to Azure Kubernetes Service. @@ -310,6 +294,8 @@ createAndConnectToAKSCluster() { } createFileShare() { + + print_step "createing fileshare" # Create a storage account echo Check if the storage account ${storageAccountName} exists. ret=$(az storage account check-name --name ${storageAccountName}) @@ -342,16 +328,8 @@ createFileShare() { # Echo storage account name and key echo Storage account name: $storageAccountName - echo NFS file share name: ${azureStorageShareName} + echo NFS file share name: ${azureStorageShareName} - # Mount the file share as a volume - echo Mounting file share as a volume. - ${KUBERNETES_CLI:-kubectl} apply -f ${scOutput} - ${KUBERNETES_CLI:-kubectl} get storageclass ${azureFileCsiNfsClassName} -o yaml - ${KUBERNETES_CLI:-kubectl} apply -f ${pvcOutput} - ${KUBERNETES_CLI:-kubectl} get pvc ${persistentVolumeClaimName} -o yaml - - checkPvcState ${persistentVolumeClaimName} "Bound" } configureStorageAccountNetwork() { @@ -370,7 +348,7 @@ configureStorageAccountNetwork() { # get the resource group name of the AKS managed resources local aksMCRGName=$(az aks show --name $aksClusterName --resource-group $azureResourceGroupName -o tsv --query "nodeResourceGroup") - echo ${aksMCRGName} + echo "aksMCRGName=${aksMCRGName}" # get network name of AKS cluster local aksNetworkName=$(az graph query -q "Resources \ @@ -378,7 +356,7 @@ configureStorageAccountNetwork() { | where resourceGroup =~ '${aksMCRGName}' \ | project name = name" --query "data[0].name" -o tsv) - echo ${aksNetworkName} + echo "aksNetworkName="${aksNetworkName} # get subnet name of AKS agent pool local aksSubnetName=$(az network vnet subnet list --resource-group ${aksMCRGName} --vnet-name ${aksNetworkName} -o tsv --query "[*].name") @@ -404,141 +382,438 @@ configureStorageAccountNetwork() { } installWebLogicOperator() { - echo $(helm version) + print_step "installing weblogic kubernetes operator" + echo "helm version ="$(helm version) helm repo add weblogic-operator https://oracle.github.io/weblogic-kubernetes-operator/charts --force-update helm install weblogic-operator weblogic-operator/weblogic-operator } createWebLogicDomain() { - # Enable the operator to monitor the namespace - ${KUBERNETES_CLI:-kubectl} label namespace default weblogic-operator=enabled + print_step "creating weblogic domain" - # Create WebLogic Server Domain Credentials. - echo Creating WebLogic Server Domain credentials, with user ${weblogicUserName}, domainUID ${domainUID} - bash ${dirCreateDomainCredentials}/create-weblogic-credentials.sh -u ${weblogicUserName} \ - -p ${weblogicAccountPassword} -d ${domainUID} - - # Create Container Registry Credentials. - bash $dirKubernetesSecrets/create-docker-credentials-secret.sh \ - -e ${docker-email} \ - -p ${dockerPassword} \ - -u ${dockerUserName} \ - -s ${imagePullSecretName} \ - -d container-registry.oracle.com + # Enable the operator to monitor the namespace + echo "Enable the operator to monitor the namespace" + ${kubernetesCli} label namespace default weblogic-operator=enabled # Create WebLogic Server Domain echo Creating WebLogic Server domain ${domainUID} - bash ${dirCreateDomain}/create-domain.sh -i $domain1Output -o ${outputDir} -e -v - ${KUBERNETES_CLI:-kubectl} apply -f ${adminLbOutput} - ${KUBERNETES_CLI:-kubectl} apply -f ${clusterLbOutput} + # create credentials + cd ${image_build_base_dir} + cd weblogic-kubernetes-operator/kubernetes/samples/scripts/create-weblogic-domain-credentials + ./create-weblogic-credentials.sh -u ${weblogicUserName} -p ${weblogicAccountPassword} -d ${domainUID} + + cd ${image_build_base_dir} + cd weblogic-kubernetes-operator/kubernetes/samples/scripts/create-kubernetes-secrets + + ./create-docker-credentials-secret.sh -s ${docker_secret_name} -e ${dockerEmail} -p ${dockerPassword} -u ${dockerEmail} + + # generate yaml + generateYamls + + # Mount the file share as a volume + echo "Mounting file share as a volume..." + ${kubernetesCli} apply -f ./azure-csi-nfs.yaml + ${kubernetesCli} apply -f ./pvc.yaml + + ${kubernetesCli} apply -f domain-resource.yaml + ${kubernetesCli} apply -f admin-lb.yaml + ${kubernetesCli} apply -f cluster-lb.yaml + +} + +generateYamls() { + +echo "generating yamls..." +cat >azure-csi-nfs.yaml <pvc.yaml <domain-resource.yaml <admin-lb.yaml <cluster-lb.yaml <" - fi + print_step "print summary" + + regionJsonExcerpt=$(az group list --query "[?name=='${azureResourceGroupName}']" | grep location) + tokens=($( + IFS='"' + for word in $regionJsonExcerpt; do echo "$word"; done + )) + region=${tokens[2]} + echo "" + echo "" + echo "The following Azure Resouces have been created: " + echo " Resource groups: ${azureResourceGroupName}, MC_${azureResourceGroupName}_${aksClusterName}_${region}" + echo " Kubernetes service cluster name: ${aksClusterName}" + echo " Storage account: ${storageAccountName}" echo "" - echo "The following files were generated:" - echo " ${scOutput}" - echo " ${pvcOutput}" - echo " ${adminLbOutput}" - echo " ${clusterLbOutput}" - echo " ${domain1Output}" + echo "Domain ${domainName} was created and was started by the WebLogic Kubernetes Operator" + echo "" + echo "Connect your ${kubernetesCli} to this cluster with this command:" + echo " az aks get-credentials --resource-group ${azureResourceGroupName} --name ${aksClusterName}" echo "" + adminLbIP=$(${kubernetesCli} get svc ${domainUID}-admin-server-external-lb --output jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo "Administration console access is available at http://${adminLbIP}:7001/console" + + echo "" + clusterLbIP=$(${kubernetesCli} get svc ${domainUID}-cluster-1-lb --output jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo "Cluster external ip is ${clusterLbIP}, you can access http://${clusterLbIP}:8001/myapp_war/index.jsp" + echo "Completed" } cd ${scriptDir} -cd .. -export dirSampleScripts=$(pwd) -export dirCreateDomain="${dirSampleScripts}/create-weblogic-domain/domain-home-on-pv" -export dirCreateDomainCredentials="${dirSampleScripts}/create-weblogic-domain-credentials" -export dirKubernetesSecrets="${dirSampleScripts}/create-kubernetes-secrets" -export selectorAdminServerName="serverName" -export selectorClusterServerName="clusterName" - -cd ${scriptDir} - # # Do these steps to create Azure resources and a WebLogic Server domain. # @@ -546,30 +821,32 @@ cd ${scriptDir} # Setup the environment for running this script and perform initial validation checks initialize -# Generate the yaml files for creating the domain -createYamlFiles +# Validate the host environment meets the prerequisites. +envValidate -# All done if the execute option is true -if [ "${executeIt}" = true ]; then +# Validate the parameters +parametersValidate "$@" - # Create resource group - createResourceGroup +# Create resource group +createResourceGroup - # Create Azure Kubernetes Service and connect to AKS cluster - createAndConnectToAKSCluster +# Create Azure Kubernetes Service and connect to AKS cluster +createAndConnectToAKSCluster - # Create File Share - createFileShare +# Create File Share +createFileShare - # Install WebLogic Operator to AKS Cluster - installWebLogicOperator +# Install WebLogic Operator to AKS Cluster +installWebLogicOperator - # Create WebLogic Server Domain - createWebLogicDomain +# Build domain image +buildDomainOnPvImage - # Wait for all the jobs completed - waitForJobComplete -fi +# Create WebLogic Server Domain +createWebLogicDomain + +# Wait for all the domain creation completed +waitForJobComplete # Print summary printSummary diff --git a/validateCLI.docker.dat b/validateCLI.docker.dat index ab3f81c4fa3..63a9d372e00 100755 --- a/validateCLI.docker.dat +++ b/validateCLI.docker.dat @@ -28,6 +28,11 @@ dockerconfigjson /docker-images/ docker-container\|ockerContainer\|DockerCluster contains."BEGIN DOCKERFILE". +dockerEmail +docker-email +dockerPassword +docker-password +weblogicDockerImage --docker-email --docker-password --docker-server