Skip to content

Commit cdce858

Browse files
authored
Merge pull request #209 from oracle/support-apache-load-balancer
Support apache load balancer
2 parents 09d5d83 + e0e9636 commit cdce858

File tree

9 files changed

+443
-8
lines changed

9 files changed

+443
-8
lines changed

kubernetes/create-weblogic-domain-inputs.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,19 @@ exposeAdminNodePort: false
8989
# Name of the domain namespace
9090
namespace: default
9191

92-
# Load balancer to deploy. Supported values are:TRAEFIK, VOYAGER, NONE
92+
# Load balancer to deploy. Supported values are: APACHE, TRAEFIK, VOYAGER, NONE
9393
loadBalancer: TRAEFIK
9494

95+
# Load balancer app prepath used for APACHE load balancer
96+
# This defines the /location in the built-in Apache plugin configuration module for WebLogic
97+
loadBalancerAppPrepath: /
98+
99+
# Docker volume path for APACHE. By default, it is empty, which causes the volume mount be
100+
# disabled and, thereforem the built-in Apache plugin config be used.
101+
# Use this to provide your own Apache plugin configuration as needed; simply define this
102+
# path and put your own custom_mod_wl_apache.conf file under this path.
103+
loadBalancerVolumePath:
104+
95105
# Load balancer web port
96106
loadBalancerWebPort: 30305
97107

kubernetes/delete-weblogic-domain-resources.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ function deleteDomains {
145145
# get a count of all k8s resources with matching domain-uid labels
146146
local allcount=`wc -l $tempfile | awk '{ print $1 }'`
147147

148-
# get a count of all WLS pods (any pod with a matching domain-uid label that doesn't have 'traefik' embedded in its name)
149-
local podcount=`grep "^Pod" $tempfile | grep -v traefik | wc -l | awk '{ print $1 }'`
148+
# get a count of all WLS pods (any pod with a matching domain-uid label that doesn't have 'traefik' or 'apache' embedded in its name)
149+
local podcount=`grep "^Pod" $tempfile | grep -v traefik | grep -v apache | wc -l | awk '{ print $1 }'`
150150

151151
local mnow=`date +%s`
152152

kubernetes/internal/create-weblogic-domain.sh

Lines changed: 102 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fi
9292
#
9393
function initAndValidateOutputDir {
9494
domainOutputDir="${outputDir}/weblogic-domains/${domainUID}"
95+
9596
validateOutputDir \
9697
${domainOutputDir} \
9798
${valuesInputFile} \
@@ -100,6 +101,8 @@ function initAndValidateOutputDir {
100101
weblogic-domain-pvc.yaml \
101102
weblogic-domain-traefik-${clusterNameLC}.yaml \
102103
weblogic-domain-traefik-security-${clusterNameLC}.yaml \
104+
weblogic-domain-apache.yaml \
105+
weblogic-domain-apache-security.yaml \
103106
create-weblogic-domain-job.yaml \
104107
domain-custom-resource.yaml
105108
}
@@ -183,12 +186,14 @@ function validateLoadBalancer {
183186
case ${loadBalancer} in
184187
"TRAEFIK")
185188
;;
189+
"APACHE")
190+
;;
186191
"VOYAGER")
187192
;;
188193
"NONE")
189194
;;
190195
*)
191-
validationError "Invalid value for loadBalancer: ${loadBalancer}. Valid values are TRAEFIK, VOYAGER and NONE."
196+
validationError "Invalid value for loadBalancer: ${loadBalancer}. Valid values are APACHE, TRAEFIK, VOYAGER and NONE."
192197
;;
193198
esac
194199
fi
@@ -341,6 +346,15 @@ function initialize {
341346
validationError "The template file ${traefikInput} for generating the traefik deployment was not found"
342347
fi
343348

349+
apacheSecurityInput="${scriptDir}/weblogic-domain-apache-security-template.yaml"
350+
if [ ! -f ${apacheSecurityInput} ]; then
351+
validationError "The file ${apacheSecurityInput} for generating the apache-webtier RBAC was not found"
352+
fi
353+
354+
apacheInput="${scriptDir}/weblogic-domain-apache-template.yaml"
355+
if [ ! -f ${apacheInput} ]; then
356+
validationError "The template file ${apacheInput} for generating the apache-webtier deployment was not found"
357+
344358
voyagerInput="${scriptDir}/voyager-ingress-template.yaml"
345359
if [ ! -f ${voyagerInput} ]; then
346360
validationError "The template file ${voyagerInput} for generating the Voyager Ingress was not found"
@@ -414,6 +428,8 @@ function createYamlFiles {
414428
dcrOutput="${domainOutputDir}/domain-custom-resource.yaml"
415429
traefikSecurityOutput="${domainOutputDir}/weblogic-domain-traefik-security-${clusterNameLC}.yaml"
416430
traefikOutput="${domainOutputDir}/weblogic-domain-traefik-${clusterNameLC}.yaml"
431+
apacheOutput="${domainOutputDir}/weblogic-domain-apache.yaml"
432+
apacheSecurityOutput="${domainOutputDir}/weblogic-domain-apache-security.yaml"
417433
voyagerOutput="${domainOutputDir}/voyager-ingress.yaml"
418434

419435
enabledPrefix="" # uncomment the feature
@@ -523,6 +539,39 @@ function createYamlFiles {
523539
sed -i -e "s:%CLUSTER_NAME_LC%:${clusterNameLC}:g" ${traefikSecurityOutput}
524540
fi
525541

542+
if [ "${loadBalancer}" = "APACHE" ]; then
543+
# Apache file
544+
cp ${apacheInput} ${apacheOutput}
545+
echo Generating ${apacheOutput}
546+
sed -i -e "s:%NAMESPACE%:$namespace:g" ${apacheOutput}
547+
sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${apacheOutput}
548+
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${apacheOutput}
549+
sed -i -e "s:%CLUSTER_NAME_LC%:${clusterNameLC}:g" ${apacheOutput}
550+
sed -i -e "s:%ADMIN_SERVER_NAME%:${adminServerName}:g" ${apacheOutput}
551+
sed -i -e "s:%ADMIN_PORT%:${adminPort}:g" ${apacheOutput}
552+
sed -i -e "s:%MANAGED_SERVER_PORT%:${managedServerPort}:g" ${apacheOutput}
553+
sed -i -e "s:%LOAD_BALANCER_WEB_PORT%:$loadBalancerWebPort:g" ${apacheOutput}
554+
sed -i -e "s:%WEB_APP_PREPATH%:$loadBalancerAppPrepath:g" ${apacheOutput}
555+
556+
if [ ! -z "${loadBalancerVolumePath}" ]; then
557+
sed -i -e "s:%LOAD_BALANCER_VOLUME_PATH%:${loadBalancerVolumePath}:g" ${apacheOutput}
558+
sed -i -e "s:# volumes:volumes:g" ${apacheOutput}
559+
sed -i -e "s:# - name:- name:g" ${apacheOutput}
560+
sed -i -e "s:# hostPath: hostPath:g" ${apacheOutput}
561+
sed -i -e "s:# path: path:g" ${apacheOutput}
562+
sed -i -e "s:# volumeMounts:volumeMounts:g" ${apacheOutput}
563+
sed -i -e "s:# - name:- name:g" ${apacheOutput}
564+
sed -i -e "s:# mountPath: mountPath:g" ${apacheOutput}
565+
fi
566+
567+
# Apache security file
568+
cp ${apacheSecurityInput} ${apacheSecurityOutput}
569+
echo Generating ${apacheSecurityOutput}
570+
sed -i -e "s:%NAMESPACE%:$namespace:g" ${apacheSecurityOutput}
571+
sed -i -e "s:%DOMAIN_UID%:${domainUID}:g" ${apacheSecurityOutput}
572+
sed -i -e "s:%DOMAIN_NAME%:${domainName}:g" ${apacheSecurityOutput}
573+
fi
574+
526575
if [ "${loadBalancer}" = "VOYAGER" ]; then
527576
# Voyager Ingress file
528577
cp ${voyagerInput} ${voyagerOutput}
@@ -724,6 +773,50 @@ function setupTraefikLoadBalancer {
724773
fi
725774
}
726775

776+
#
777+
# Deploy Apache load balancer
778+
#
779+
function setupApacheLoadBalancer {
780+
781+
apacheName="${domainUID}-apache-webtier"
782+
783+
echo Setting up apache security
784+
kubectl apply -f ${apacheSecurityOutput}
785+
786+
echo Checking the cluster role ${apacheName} was created
787+
CLUSTERROLE=`kubectl get clusterroles | grep ${apacheName} | wc | awk ' { print $1; } '`
788+
if [ "$CLUSTERROLE" != "1" ]; then
789+
fail "The cluster role ${apacheName} was not created"
790+
fi
791+
792+
echo Checking the cluster role binding ${apacheName} was created
793+
CLUSTERROLEBINDING=`kubectl get clusterrolebindings | grep ${apacheName} | wc | awk ' { print $1; } '`
794+
if [ "$CLUSTERROLEBINDING" != "1" ]; then
795+
fail "The cluster role binding ${apacheName} was not created"
796+
fi
797+
798+
echo Deploying apache
799+
kubectl apply -f ${apacheOutput}
800+
801+
echo Checking apache deployment
802+
SS=`kubectl get deployment -n ${namespace} | grep ${apacheName} | wc | awk ' { print $1; } '`
803+
if [ "$SS" != "1" ]; then
804+
fail "The deployment ${apacheName} was not created"
805+
fi
806+
807+
echo Checking the apache service account
808+
SA=`kubectl get serviceaccount ${apacheName} -n ${namespace} | grep ${apacheName} | wc | awk ' { print $1; } '`
809+
if [ "$SA" != "1" ]; then
810+
fail "The service account ${apacheName} was not created"
811+
fi
812+
813+
echo Checking apache service
814+
TSVC=`kubectl get services -n ${namespace} | grep ${apacheName} | wc | awk ' { print $1; } '`
815+
if [ "$TSVC" != "1" ]; then
816+
fail "The service ${apacheServiceName} was not created"
817+
fi
818+
}
819+
727820
#
728821
# Function to create the domain custom resource
729822
#
@@ -782,6 +875,9 @@ function outputJobSummary {
782875
echo "The load balancer for cluster '${clusterName}' is available at http:${K8S_IP}:${loadBalancerWebPort}/ (add the application path to the URL)"
783876
echo "The load balancer dashboard for cluster '${clusterName}' is available at http:${K8S_IP}:${loadBalancerDashboardPort}"
784877
echo ""
878+
elif [ "${loadBalancer}" = "APACHE" ]; then
879+
echo "The apache load balancer for '${domainUID}' is available at http:${K8S_IP}:${loadBalancerWebPort}/ (add the application path to the URL)"
880+
785881
fi
786882
echo "The following files were generated:"
787883
echo " ${domainOutputDir}/create-weblogic-domain-inputs.yaml"
@@ -792,6 +888,9 @@ function outputJobSummary {
792888
if [ "${loadBalancer}" = "TRAEFIK" ]; then
793889
echo " ${traefikSecurityOutput}"
794890
echo " ${traefikOutput}"
891+
elif [ "${loadBalancer}" = "APACHE" ]; then
892+
echo " ${apacheSecurityOutput}"
893+
echo " ${apacheOutput}"
795894
elif [ "${loadBalancer}" = "VOYAGER" ]; then
796895
echo " ${voyagerOutput}"
797896
fi
@@ -824,6 +923,8 @@ if [ "${generateOnly}" = false ]; then
824923
# Setup load balancer
825924
if [ "${loadBalancer}" = "TRAEFIK" ]; then
826925
setupTraefikLoadBalancer
926+
elif [ "${loadBalancer}" = "APACHE" ]; then
927+
setupApacheLoadBalancer
827928
elif [ "${loadBalancer}" = "VOYAGER" ]; then
828929
setupVoyagerLoadBalancer
829930
fi
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
kind: ClusterRole
3+
apiVersion: rbac.authorization.k8s.io/v1beta1
4+
metadata:
5+
name: %DOMAIN_UID%-apache-webtier
6+
labels:
7+
weblogic.domainUID: %DOMAIN_UID%
8+
weblogic.domainName: %DOMAIN_NAME%
9+
rules:
10+
- apiGroups:
11+
- ""
12+
resources:
13+
- pods
14+
- services
15+
- endpoints
16+
- secrets
17+
verbs:
18+
- get
19+
- list
20+
- watch
21+
- apiGroups:
22+
- extensions
23+
resources:
24+
- ingresses
25+
verbs:
26+
- get
27+
- list
28+
- watch
29+
---
30+
kind: ClusterRoleBinding
31+
apiVersion: rbac.authorization.k8s.io/v1beta1
32+
metadata:
33+
name: %DOMAIN_UID%-apache-webtier
34+
labels:
35+
weblogic.domainUID: %DOMAIN_UID%
36+
weblogic.domainName: %DOMAIN_NAME%
37+
roleRef:
38+
apiGroup: rbac.authorization.k8s.io
39+
kind: ClusterRole
40+
name: %DOMAIN_UID%-apache-webtier
41+
subjects:
42+
- kind: ServiceAccount
43+
name: %DOMAIN_UID%-apache-webtier
44+
namespace: %NAMESPACE%
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: %DOMAIN_UID%-apache-webtier
6+
namespace: %NAMESPACE%
7+
labels:
8+
weblogic.domainUID: %DOMAIN_UID%
9+
weblogic.domainName: %DOMAIN_NAME%
10+
app: apache-webtier
11+
---
12+
kind: Deployment
13+
apiVersion: extensions/v1beta1
14+
metadata:
15+
name: %DOMAIN_UID%-apache-webtier
16+
namespace: %NAMESPACE%
17+
labels:
18+
weblogic.domainUID: %DOMAIN_UID%
19+
weblogic.domainName: %DOMAIN_NAME%
20+
app: apache-webtier
21+
spec:
22+
replicas: 1
23+
selector:
24+
matchLabels:
25+
weblogic.domainUID: %DOMAIN_UID%
26+
weblogic.domainName: %DOMAIN_NAME%
27+
app: apache-webtier
28+
template:
29+
metadata:
30+
labels:
31+
weblogic.domainUID: %DOMAIN_UID%
32+
weblogic.domainName: %DOMAIN_NAME%
33+
app: apache-webtier
34+
spec:
35+
serviceAccountName: %DOMAIN_UID%-apache-webtier
36+
terminationGracePeriodSeconds: 60
37+
# volumes:
38+
# - name: "%DOMAIN_UID%-apache-webtier"
39+
# hostPath:
40+
# path: %LOAD_BALANCER_VOLUME_PATH%
41+
containers:
42+
- name: %DOMAIN_UID%-apache-webtier
43+
image: 12213-apache:latest
44+
imagePullPolicy: Never
45+
# volumeMounts:
46+
# - name: "%DOMAIN_UID%-apache-webtier"
47+
# mountPath: "/config"
48+
env:
49+
- name: WEBLOGIC_CLUSTER
50+
value: '%DOMAIN_UID%-cluster-%CLUSTER_NAME_LC%:%MANAGED_SERVER_PORT%'
51+
- name: LOCATION
52+
value: '%WEB_APP_PREPATH%'
53+
- name: WEBLOGIC_HOST
54+
value: '%DOMAIN_UID%-%ADMIN_SERVER_NAME%'
55+
- name: WEBLOGIC_PORT
56+
value: '%ADMIN_PORT%'
57+
readinessProbe:
58+
tcpSocket:
59+
port: 80
60+
failureThreshold: 1
61+
initialDelaySeconds: 10
62+
periodSeconds: 10
63+
successThreshold: 1
64+
timeoutSeconds: 2
65+
livenessProbe:
66+
tcpSocket:
67+
port: 80
68+
failureThreshold: 3
69+
initialDelaySeconds: 10
70+
periodSeconds: 10
71+
successThreshold: 1
72+
timeoutSeconds: 2
73+
74+
---
75+
apiVersion: v1
76+
kind: Service
77+
metadata:
78+
name: %DOMAIN_UID%-apache-webtier
79+
namespace: %NAMESPACE%
80+
labels:
81+
weblogic.domainUID: %DOMAIN_UID%
82+
weblogic.domainName: %DOMAIN_NAME%
83+
spec:
84+
type: NodePort
85+
selector:
86+
weblogic.domainUID: %DOMAIN_UID%
87+
weblogic.domainName: %DOMAIN_NAME%
88+
app: apache-webtier
89+
ports:
90+
- port: 80
91+
nodePort: %LOAD_BALANCER_WEB_PORT%
92+
name: rest-https
93+

operator/src/test/java/oracle/kubernetes/operator/create/CreateDomainInputs.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class CreateDomainInputs {
2929

3030
public static final String LOAD_BALANCER_NONE = "NONE";
3131
public static final String LOAD_BALANCER_TRAEFIK = "TRAEFIK";
32+
public static final String LOAD_BALANCER_APACHE = "APACHE";
3233
public static final String STORAGE_TYPE_HOST_PATH = "HOST_PATH";
3334
public static final String STORAGE_TYPE_NFS = "NFS";
3435
public static final String STORAGE_RECLAIM_POLICY_RETAIN = "Retain";
@@ -72,6 +73,8 @@ public class CreateDomainInputs {
7273
private String loadBalancer = "";
7374
private String loadBalancerWebPort = "";
7475
private String loadBalancerDashboardPort = "";
76+
private String loadBalancerVolumePath = "";
77+
private String loadBalancerAppPrepath = "";
7578
private String javaOptions = "";
7679

7780
public static CreateDomainInputs newInputs() throws Exception {
@@ -492,6 +495,32 @@ public CreateDomainInputs loadBalancerDashboardPort(String loadBalancerDashboard
492495
return this;
493496
}
494497

498+
public String getLoadBalancerVolumePath() {
499+
return loadBalancerVolumePath;
500+
}
501+
502+
public void setLoadBalancerVolumePath(String loadBalancerVolumePath) {
503+
this.loadBalancerVolumePath = convertNullToEmptyString(loadBalancerVolumePath);
504+
}
505+
506+
public CreateDomainInputs loadBalancerVolumePath(String loadBalancerVolumePath) {
507+
setLoadBalancerVolumePath(loadBalancerVolumePath);
508+
return this;
509+
}
510+
511+
public String getLoadBalancerAppPrepath() {
512+
return loadBalancerAppPrepath;
513+
}
514+
515+
public void setLoadBalancerAppPrepath(String loadBalancerAppPrepath) {
516+
this.loadBalancerAppPrepath = convertNullToEmptyString(loadBalancerAppPrepath);
517+
}
518+
519+
public CreateDomainInputs loadBalancerAppPrepath(String loadBalancerAppPrepath) {
520+
setLoadBalancerAppPrepath(loadBalancerAppPrepath);
521+
return this;
522+
}
523+
495524
public String getJavaOptions() {
496525
return javaOptions;
497526
}

0 commit comments

Comments
 (0)