|
| 1 | +# Apache Load Balancer custom sample |
| 2 | +In this sample, we will configure Apache webtier as a load balancer for multiple WebLogic domains using custom configuration. We will demonstrate how to use Apache webtier to handle traffic to the multiple backend WebLogic domains. |
| 3 | + |
| 4 | +## 1. Create Namespace |
| 5 | +In this sample, both Apache webtier and WebLogic domain instances are located in the namespace `apache-sample`. |
| 6 | +``` |
| 7 | +$ kubectl create namespace apache-sample |
| 8 | +``` |
| 9 | + |
| 10 | +## 2. Create WebLogic Domains |
| 11 | +Now we need to prepare some backends for Apache webtier to do load balancing. Please refer the sample https://github.com/oracle/weblogic-kubernetes-operator/tree/develop/kubernetes/samples/scripts/create-weblogic-domain/domain-home-on-pv 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 through the admin console. The sample web application is located in the kubernetes/samples/charts/application directory. |
| 32 | + |
| 33 | +## 3. Build Apache Webtier Docker Image |
| 34 | +Please refer the sample https://github.com/oracle/docker-images/tree/master/OracleWebLogic/samples/12213-webtier-apache to build Apache webtier docker image. |
| 35 | + |
| 36 | +## 4. Provide Custom Apache Plugin Configuration |
| 37 | +In this sample we will provide custom Apache plugin configuration to fine tune the behavior of Apache. |
| 38 | +- Create a custom Apache plugin configuration file named `custom_mod_wl_apache.conf`. The file content is similar as below. |
| 39 | +``` |
| 40 | +# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. |
| 41 | +# |
| 42 | +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 43 | +# |
| 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 | +- Place the `custom_mod_wl_apache.conf` file in a local directory `<host-config-dir>` on the host machine. |
| 81 | + |
| 82 | +## 5. Prepare Your Own Certificate and Private Key |
| 83 | +In production, Oracle strongly recommends that you provide your own certificates. Run following commands to to generate your own certificate and private key using openssl. |
| 84 | +``` |
| 85 | +$ cd kubernetes/samples/charts/apache-samples/custom-sample |
| 86 | +$ export VIRTUAL_HOST_NAME=apache-sample-host |
| 87 | +$ export SSL_CERT_FILE=apache-sample.crt |
| 88 | +$ export SSL_CERT_KEY_FILE=apache-sample.key |
| 89 | +$ sh certgen.sh |
| 90 | +``` |
| 91 | + |
| 92 | +## 6. Prepare the Input Values for Apache Webtier Helm Chart |
| 93 | +Run following commands to prepare the input value file for Apache webtier helm chart. |
| 94 | +``` |
| 95 | +$ base64 -i ${SSL_CERT_FILE} | tr -d '\n' |
| 96 | +$ base64 -i ${SSL_CERT_KEY_FILE} | tr -d '\n' |
| 97 | +$ touch input.yaml |
| 98 | +``` |
| 99 | +Edit the input parameters file `input.yaml`, the file content is similar as below. |
| 100 | +``` |
| 101 | +# Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved. |
| 102 | +# |
| 103 | +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 104 | +
|
| 105 | +# Use this to provide your own Apache webtier configuration as needed; simply define this |
| 106 | +# path and put your own custom_mod_wl_apache.conf file under this path. |
| 107 | +volumePath: <host-config-dir> |
| 108 | +
|
| 109 | +# The VirtualHostName of the Apache HTTP server. It is used to enable custom SSL configuration. |
| 110 | +virtualHostName: apache-sample-host |
| 111 | +
|
| 112 | +# The customer supplied certificate to use for Apache webtier SSL configuration. |
| 113 | +# The value must be a string containing a base64 encoded certificate. Run following command to get it. |
| 114 | +# base64 -i ${SSL_CERT_FILE} | tr -d '\n' |
| 115 | +customCert: <cert_data> |
| 116 | +
|
| 117 | +# The customer supplied private key to use for Apache webtier SSL configuration. |
| 118 | +# The value must be a string containing a base64 encoded key. Run following command to get it. |
| 119 | +# base64 -i ${SSL_KEY_FILE} | tr -d '\n' |
| 120 | +customKey: <key_data> |
| 121 | +``` |
| 122 | + |
| 123 | +## 7. Install Apache Webtier Helm Chart |
| 124 | +Apache webtier helm chart is located in kubernetes/samples/charts/apache-webtier directory. Install Apache webtier helm chart to apache-sample namespace with specified input parameters: |
| 125 | +``` |
| 126 | +$ cd kubernetes/samples/charts |
| 127 | +$ helm install --name my-release --values apache-samples/custom-sample/input.yaml --namespace apache-sample apache-webtier |
| 128 | +``` |
| 129 | + |
| 130 | +## 8. Run the Sample Application |
| 131 | +Now you can send requests to different WebLogic domains with the unique entry point of Apache with different path. Alternatively, you can access the URLs in a web browser. |
| 132 | +``` |
| 133 | +$ curl --silent http://${HOSTNAME}:30305/weblogic1/testwebapp/ |
| 134 | +$ curl --silent http://${HOSTNAME}:30305/weblogic2/testwebapp/ |
| 135 | +``` |
| 136 | +You can also use SSL URLs to send requests to different WebLogic domains. Access the SSL URL via the curl command or a web browser. |
| 137 | +``` |
| 138 | +$ curl -k --silent https://${HOSTNAME}:30443/weblogic1/testwebapp/ |
| 139 | +$ curl -k --silent https://${HOSTNAME}:30443/weblogic2/testwebapp/ |
| 140 | +``` |
| 141 | + |
| 142 | +## 9. Uninstall Apache Webtier |
| 143 | +``` |
| 144 | +$ helm delete --purge my-release |
| 145 | +``` |
0 commit comments