|
| 1 | +# Apache load balancer custom sample |
| 2 | +In this sample, we will configure the Apache webtier as a load balancer for multiple WebLogic domains using a custom configuration. We will demonstrate how to use the Apache webtier to handle traffic to multiple backend WebLogic domains. |
| 3 | + |
| 4 | +## 1. Create a namespace |
| 5 | +In this sample, both the Apache webtier and WebLogic domain instances are located in the namespace `apache-sample`. |
| 6 | +```shell |
| 7 | +$ kubectl create namespace apache-sample |
| 8 | +``` |
| 9 | + |
| 10 | +## 2. Create WebLogic domains |
| 11 | +We need to prepare some backend domains for load balancing by the Apache webtier. Refer to the [sample](/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv/README.md), to create two WebLogic domains under the namespace `apache-sample`. |
| 12 | + |
| 13 | +The first domain uses the following custom configuration parameters: |
| 14 | +- namespace: `apache-sample` |
| 15 | +- domainUID: `domain1` |
| 16 | +- clusterName: `cluster-1` |
| 17 | +- adminServerName: `admin-server` |
| 18 | +- adminPort: `7001` |
| 19 | +- adminNodePort: `30701` |
| 20 | +- managedServerPort: `8001` |
| 21 | + |
| 22 | +The second domain uses the following custom configuration parameters: |
| 23 | +- namespace: `apache-sample` |
| 24 | +- domainUID: `domain2` |
| 25 | +- clusterName: `cluster-1` |
| 26 | +- adminServerName: `admin-server` |
| 27 | +- adminPort: `7011` |
| 28 | +- adminNodePort: `30702` |
| 29 | +- managedServerPort: `8021` |
| 30 | + |
| 31 | +After the domains are successfully created, deploy the sample web application, `testwebapp.war`, on each domain cluster using the WLS Administration Console. The sample web application is located in the `kubernetes/samples/charts/application` directory. |
| 32 | + |
| 33 | +## 3. Build the Apache webtier Docker image |
| 34 | +Refer to the [sample](https://github.com/oracle/docker-images/tree/master/OracleWebLogic/samples/12213-webtier-apache), to build the Apache webtier Docker image. |
| 35 | + |
| 36 | +## 4. Provide the custom Apache plugin configuration |
| 37 | +In this sample, we will provide a custom Apache plugin configuration to fine tune the behavior of Apache. |
| 38 | + |
| 39 | +* Create a custom Apache plugin configuration file named `custom_mod_wl_apache.conf`. The file content is similar to below. |
| 40 | + |
| 41 | +``` |
| 42 | +# Copyright (c) 2018, 2021, Oracle and/or its affiliates. |
| 43 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 44 | +
|
| 45 | +<IfModule mod_weblogic.c> |
| 46 | +WebLogicHost ${WEBLOGIC_HOST} |
| 47 | +WebLogicPort ${WEBLOGIC_PORT} |
| 48 | +</IfModule> |
| 49 | +
|
| 50 | +# Directive for weblogic admin Console deployed on Weblogic Admin Server |
| 51 | +<Location /console> |
| 52 | +SetHandler weblogic-handler |
| 53 | +WebLogicHost domain1-admin-server |
| 54 | +WebLogicPort ${WEBLOGIC_PORT} |
| 55 | +</Location> |
| 56 | +
|
| 57 | +# Directive for all application deployed on weblogic cluster with a prepath defined by LOCATION variable |
| 58 | +# For example, if the LOCAITON is set to '/weblogic', all applications deployed on the cluster can be accessed via |
| 59 | +# http://myhost:myport/weblogic/application_end_url |
| 60 | +# where 'myhost' is the IP of the machine that runs the Apache web tier, and |
| 61 | +# 'myport' is the port that the Apache web tier is publicly exposed to. |
| 62 | +# Note that LOCATION cannot be set to '/' unless this is the only Location module configured. |
| 63 | +<Location /weblogic1> |
| 64 | +WLSRequest On |
| 65 | +WebLogicCluster domain1-cluster-cluster-1:8001 |
| 66 | +PathTrim /weblogic1 |
| 67 | +</Location> |
| 68 | +
|
| 69 | +# Directive for all application deployed on weblogic cluster with a prepath defined by LOCATION2 variable |
| 70 | +# For example, if the LOCAITON2 is set to '/weblogic2', all applications deployed on the cluster can be accessed via |
| 71 | +# http://myhost:myport/weblogic2/application_end_url |
| 72 | +# where 'myhost' is the IP of the machine that runs the Apache web tier, and |
| 73 | +# 'myport' is the port that the Apache webt ier is publicly exposed to. |
| 74 | +<Location /weblogic2> |
| 75 | +WLSRequest On |
| 76 | +WebLogicCluster domain2-cluster-cluster-1:8021 |
| 77 | +PathTrim /weblogic2 |
| 78 | +</Location> |
| 79 | +``` |
| 80 | + |
| 81 | +* Create a PV / PVC (pv-claim-name) that can be used to store the `custom_mod_wl_apache.conf`. Refer to the [Sample for creating a PV or PVC](/kubernetes/samples/scripts/create-weblogic-domain-pv-pvc/README.md). |
| 82 | + |
| 83 | +## 5. Prepare your own certificate and private key |
| 84 | +In production, Oracle strongly recommends that you provide your own certificates. Run the following commands to generate your own certificate and private key using `openssl`. |
| 85 | + |
| 86 | +```shell |
| 87 | +$ cd kubernetes/samples/charts/apache-samples/custom-sample |
| 88 | +$ export VIRTUAL_HOST_NAME=apache-sample-host |
| 89 | +$ export SSL_CERT_FILE=apache-sample.crt |
| 90 | +$ export SSL_CERT_KEY_FILE=apache-sample.key |
| 91 | +$ sh certgen.sh |
| 92 | +``` |
| 93 | + |
| 94 | +## 6. Prepare the input values for the Apache webtier Helm chart |
| 95 | +Run the following commands to prepare the input value file for the Apache webtier Helm chart. |
| 96 | + |
| 97 | +```shell |
| 98 | +$ base64 -i ${SSL_CERT_FILE} | tr -d '\n' |
| 99 | +$ base64 -i ${SSL_CERT_KEY_FILE} | tr -d '\n' |
| 100 | +$ touch input.yaml |
| 101 | +``` |
| 102 | +Edit the input parameters file, `input.yaml`. The file content is similar to below. |
| 103 | + |
| 104 | +```yaml |
| 105 | +# Copyright (c) 2018, 2021, Oracle and/or its affiliates. |
| 106 | +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 107 | + |
| 108 | +# Use this to provide your own Apache webtier configuration as needed; simply define this |
| 109 | +# Persistence Volume which contains your own custom_mod_wl_apache.conf file. |
| 110 | +persistentVolumeClaimName: <pv-claim-name> |
| 111 | + |
| 112 | +# The VirtualHostName of the Apache HTTP server. It is used to enable custom SSL configuration. |
| 113 | +virtualHostName: apache-sample-host |
| 114 | + |
| 115 | +# The customer supplied certificate to use for Apache webtier SSL configuration. |
| 116 | +# The value must be a string containing a base64 encoded certificate. Run following command to get it. |
| 117 | +# base64 -i ${SSL_CERT_FILE} | tr -d '\n' |
| 118 | +customCert: <cert_data> |
| 119 | + |
| 120 | +# The customer supplied private key to use for Apache webtier SSL configuration. |
| 121 | +# The value must be a string containing a base64 encoded key. Run following command to get it. |
| 122 | +# base64 -i ${SSL_KEY_FILE} | tr -d '\n' |
| 123 | +customKey: <key_data> |
| 124 | +``` |
| 125 | +
|
| 126 | +## 7. Install the Apache webtier Helm chart |
| 127 | +The Apache webtier Helm chart is located in the `kubernetes/samples/charts/apache-webtier` directory. Install the Apache webtier Helm chart to the `apache-sample` namespace with the specified input parameters: |
| 128 | + |
| 129 | +```shell |
| 130 | +$ cd kubernetes/samples/charts |
| 131 | +$ helm install my-release --values apache-samples/custom-sample/input.yaml --namespace apache-sample apache-webtier |
| 132 | +``` |
| 133 | + |
| 134 | +## 8. Run the sample application |
| 135 | +Now you can send requests to different WebLogic domains with the unique entry point of Apache with different paths. Alternatively, you can access the URLs in a web browser. |
| 136 | +```shell |
| 137 | +$ curl --silent http://${HOSTNAME}:30305/weblogic1/testwebapp/ |
| 138 | +$ curl --silent http://${HOSTNAME}:30305/weblogic2/testwebapp/ |
| 139 | +``` |
| 140 | +Also, you can use SSL URLs to send requests to different WebLogic domains. Access the SSL URL via the `curl` command or a web browser. |
| 141 | +```shell |
| 142 | +$ curl -k --silent https://${HOSTNAME}:30443/weblogic1/testwebapp/ |
| 143 | +$ curl -k --silent https://${HOSTNAME}:30443/weblogic2/testwebapp/ |
| 144 | +``` |
| 145 | + |
| 146 | +## 9. Uninstall the Apache webtier |
| 147 | +```shell |
| 148 | +$ helm uninstall my-release --namespace apache-sample |
| 149 | +``` |
0 commit comments