|
| 1 | +# WebLogic Sample Domain Home in Docker Image |
| 2 | + |
| 3 | +The sample scripts demonstrate the creation of a WebLogic domain home in docker image. The scripts also generate the domain YAML file, which can then be used to start the Kubernetes artifacts of the corresponding domain. Optionally, the scripts start up the domain, and WebLogic Server pods and services. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +The following prerequisites must be handled prior to running the create domain script: |
| 8 | +* Make sure the WebLogic Operator is running. |
| 9 | +* Create a Kubernetes namespace for the domain unless the intention is to use the default namespace. |
| 10 | +* Create the Kubernetes secrets `username` and `password` of the admin account in the same Kubernetes namespace as the domain. |
| 11 | +* Build the Oracle WebLogic image oracle/weblogic:12.2.1.3-developer . Refer to [Oracle WebLogic Server on Docker](https://github.com/oracle/docker-images/tree/master/OracleWebLogic/dockerfiles/12.2.1.3). |
| 12 | + |
| 13 | +## Using the script to create a domain |
| 14 | + |
| 15 | +Make a copy of the `create-domain-inputs.yaml` file, and run the create script, pointing it at your inputs file and an output directory: |
| 16 | + |
| 17 | +``` |
| 18 | + ./create-domain.sh \ |
| 19 | + -i create-domain-inputs.yaml \ |
| 20 | + -o /path/to/output-directory |
| 21 | +``` |
| 22 | + |
| 23 | +The script will perform the following steps: |
| 24 | + |
| 25 | +* Create a directory for the generated properties and Kubernetes YAML files for this domain if it does not already exist. The pathname is `/path/to/weblogic-operator-output-directory/weblogic-domains/<domainUID>`. Note that the script fails if the directory is not empty when the `create-domain.sh` script is executed. |
| 26 | +* Create a proerties file, `domain.properties`, in the directory that is created above. This properties file will be used to create a sample WebLogic Server domain. |
| 27 | +* Build Docker image based on Docker sample [Example Image with a WebLogic Server Domain](https://github.com/oracle/docker-images/tree/master/OracleWebLogic/samples/12213-domain-home-in-image). It will create a sample WebLogic Server domain into the Docker image. You can also run the Docker sample [Example Image with a WebLogic Server Domain](https://github.com/oracle/docker-images/tree/master/OracleWebLogic/samples/12213-domain-home-in-image) manually with the generated `domain.properties` to create domain home image. Note: Oracle recommends keeping the domain home image private in the local repository. |
| 28 | +* Create a Kubernetes domain YAML file, `domain.yaml`, in the directory that is created above. This YAML file can be used to create the Kubernetes resource using the `kubectl create -f` or `kubectl apply -f` command. |
| 29 | + |
| 30 | +As a convenience, using the `-e` option, the script can optionally create the domain object, which in turn results in the creation of the corresponding WebLogic Server pods and services as well. |
| 31 | + |
| 32 | +The usage of the create script is as follows: |
| 33 | + |
| 34 | +``` |
| 35 | +$ sh create-domain.sh -h |
| 36 | +usage: create-domain.sh -o dir -i file [-e] [-h] |
| 37 | + -i Parameter inputs file, must be specified. |
| 38 | + -o Output directory for the generated properties and YAML files, must be specified. |
| 39 | + -e Also create the resources in the generated YAML file, optional. |
| 40 | + -h Help |
| 41 | +
|
| 42 | +``` |
| 43 | + |
| 44 | +If you copy the sample scripts to a different location, make sure that you copy everything in the `<weblogic-kubernetes-operator-project>/kubernetes/samples/scripts` directory together into the target directory, maintaining the original directory hierarchy. |
| 45 | + |
| 46 | +The default domain created by the script has the following characteristics: |
| 47 | + |
| 48 | +* An Administration Server named `admin-server` listening on port `7001`. |
| 49 | +* A dynamic cluster named `cluster-1` of size 2. |
| 50 | +* Two Managed Servers, named `managed-server1` and `managed-server2`, listening on port `8001`. |
| 51 | +* No applications deployed. |
| 52 | +* A Derby data source. |
| 53 | +* A T3 channel. |
| 54 | + |
| 55 | +The domain creation inputs can be customized by editing `create-domain-inputs.yaml`. |
| 56 | + |
| 57 | +### Configuration parameters |
| 58 | +The following parameters can be provided in the inputs file. |
| 59 | + |
| 60 | +| Parameter | Definition | Default | |
| 61 | +| --- | --- | --- | |
| 62 | +| `adminPort` | Port number for the Administration Server inside the Kubernetes cluster. | `7001` | |
| 63 | +| `adminNodePort` | Port number of the Administration Server outside the Kubernetes cluster. | `30701` | |
| 64 | +| `adminServerName` | Name of the Administration Server. | `admin-server` | |
| 65 | +| `clusterName` | Name of the WebLogic cluster instance to generate for the domain. | `cluster-1` | |
| 66 | +| `clusterType` | Type of the WebLogic Cluster. Legal values are `CONFIGURED` or `DYNAMIC`. | `DYNAMIC` | |
| 67 | +| `configuredManagedServerCount` | Number of Managed Server instances to generate for the domain. | `2` | |
| 68 | +| `domainUID` | Unique ID that will be used to identify this particular domain. Used as the name of the generated WebLogic domain as well as the name of the Kubernetes domain resource. This ID must be unique across all domains in a Kubernetes cluster. This ID cannot contain any character that is not valid in a Kubernetes service name. | `domain1` | |
| 69 | +| `exposeAdminNodePort` | Boolean indicating if the Administration Server is exposed outside of the Kubernetes cluster. | `false` | |
| 70 | +| `exposeAdminT3Channel` | Boolean indicating if the T3 administrative channel is exposed outside the Kubernetes cluster. | `false` | |
| 71 | +| `initialManagedServerReplicas` | Number of Managed Servers to initially start for the domain. | `2` | |
| 72 | +| `javaOptions` | Java options for starting the Administration and Managed Servers. A Java option can have references to one or more of the following pre-defined variables to obtain WebLogic domain information: `$(DOMAIN_NAME)`, `$(DOMAIN_HOME)`, `$(ADMIN_NAME)`, `$(ADMIN_PORT)`, and `$(SERVER_NAME)`. | `-Dweblogic.StdoutDebugEnabled=false` | |
| 73 | +| `managedServerNameBase` | Base string used to generate Managed Server names. | `managed-server` | |
| 74 | +| `managedServerPort` | Port number for each Managed Server. | `8001` | |
| 75 | +| `namespace` | Kubernetes namespace in which to create the domain. | `default` | |
| 76 | +| `productionModeEnabled` | Boolean indicating if production mode is enabled for the domain. | `true` | |
| 77 | +| `serverStartPolicy` | Determines which WebLogic Servers will be started up. Legal values are `NEVER`, `ALWAYS`, `IF_NEEDED`, `ADMIN_ONLY`. | `IF_NEEDED` | |
| 78 | +| `t3ChannelPort` | Port for the T3 channel of the NetworkAccessPoint. | `30012` | |
| 79 | +| `t3PublicAddress` | Public address for the T3 channel. | `kubernetes` | |
| 80 | +| `weblogicCredentialsSecretName` | Name of the Kubernetes secret for the Administration Server's username and password. | `domain1-weblogic-credentials` | |
| 81 | +| `includeServerOutInPodLog` | Boolean indicating whether to include server .out to the pod's stdout. | `true` | |
| 82 | + |
| 83 | +Note that the names of the Kubernetes resources in the generated YAML files may be formed with the value of some of the properties specified in the `create-inputs.yaml` file. Those properties include the `adminServerName`, `clusterName` and `managedServerNameBase`. If those values contain any characters that are invalid in a Kubernetes service name, those characters are converted to valid values in the generated YAML files. For example, an uppercase letter is converted to a lowercase letter and an underscore `("_")` is converted to a hyphen `("-")`. |
| 84 | + |
| 85 | +The sample demonstrates how to create a WebLogic domain home and associated Kubernetes resources for a domain that only has one cluster. In addition, the sample provides the capability for users to supply their own scripts to create the domain home for other use cases. The generated domain YAML file could also be modified to cover more use cases. |
| 86 | + |
| 87 | +## Verify the results |
| 88 | + |
| 89 | +The create script will verify that the domain was created, and will report failure if there was any error. However, it may be desirable to manually verify the domain, even if just to gain familiarity with the various Kubernetes objects that were created by the script. |
| 90 | + |
| 91 | +Note that the example results below uses the `default` Kubernetes namespace. If you are using a different namespace, you need to replace `NAMESPACE` in the example `kubectl` commands with the actual Kubernetes namespace. |
| 92 | + |
| 93 | +### Generated YAML files with the default inputs |
| 94 | + |
| 95 | +The content of the generated `domain.yaml`: |
| 96 | + |
| 97 | +``` |
| 98 | +# Copyright 2017, 2018, Oracle Corporation and/or its affiliates. All rights reserved. |
| 99 | +# Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. |
| 100 | +# |
| 101 | +# This is an example of how to define a Domain resource. |
| 102 | +# |
| 103 | +apiVersion: "weblogic.oracle/v2" |
| 104 | +kind: Domain |
| 105 | +metadata: |
| 106 | + name: domain1 |
| 107 | + namespace: default |
| 108 | + labels: |
| 109 | + weblogic.resourceVersion: domain-v2 |
| 110 | + weblogic.domainUID: domain1 |
| 111 | + weblogic.domainName: domain1 |
| 112 | +spec: |
| 113 | + # The domainUID must be unique across the entire Kubernetes Cluster. Each WebLogic Domain must |
| 114 | + # have its own unique domainUID. This does not have to be the same as the Domain Name. It is allowed |
| 115 | + # to have multiple Domains with the same Domain Name, but they MUST have different domainUID's. |
| 116 | + # The domainUID is also used to identify the Persistent Volume that belongs to/with this Domain. |
| 117 | + domainUID: domain1 |
| 118 | + # The WebLogic Domain Name |
| 119 | + domainName: domain1 |
| 120 | + # The WebLogic Domain Home |
| 121 | + domainHome: /u01/oracle/user_projects/domains/domain1 |
| 122 | + # If the domain home is in the image |
| 123 | + domainHomeInImage: true |
| 124 | + # The Operator currently does not support other images |
| 125 | + image: "12213-domain-home-in-image:latest" |
| 126 | + # imagePullPolicy defaults to "Never" |
| 127 | + imagePullPolicy: "Never" |
| 128 | + # Identify which Secret contains the WebLogic Admin credentials (note that there is an example of |
| 129 | + # how to create that Secret at the end of this file) |
| 130 | + adminSecret: |
| 131 | + name: domain1-weblogic-credentials |
| 132 | + # The name of the Admin Server |
| 133 | + asName: "admin-server" |
| 134 | + # The Admin Server's ListenPort |
| 135 | + asPort: 7001 |
| 136 | + # Whether to include the server out file into the pod's stdout, default is true |
| 137 | + includeServerOutInPodLog: true |
| 138 | + # serverStartPolicy legal values are "NEVER", "ALWAYS", "IF_NEEDED", or "ADMIN_ONLY" |
| 139 | + # This determines which WebLogic Servers the Operator will start up when it discovers this Domain |
| 140 | + # - "ALWAYS" will start up all defined servers |
| 141 | + # - "ADMIN_ONLY" will start up only the administration server (no managed servers will be started) |
| 142 | + # - "IF_NEEDED" will start all non-clustered servers, including the administration server and clustered servers up to the replica count |
| 143 | + serverStartPolicy: "IF_NEEDED" |
| 144 | + # adminServer is used to configure the desired behavior for starting the administration server. |
| 145 | + adminServer: |
| 146 | + # serverStartState legal values are "RUNNING" or "ADMIN" |
| 147 | + # "RUNNING" means the listed server will be started up to "RUNNING" mode |
| 148 | + # "ADMIN" means the listed server will be start up to "ADMIN" mode |
| 149 | + serverStartState: "RUNNING" |
| 150 | + # The Admin Server's NodePort |
| 151 | + # nodePort: 30701 |
| 152 | + # Uncomment to export the T3Channel as a service |
| 153 | + # exportedNetworkAccessPoints: |
| 154 | + # T3Channel: {} |
| 155 | + # an (optional) list of environment variable to be set on the server |
| 156 | + env: |
| 157 | + - name: JAVA_OPTIONS |
| 158 | + value: "-Dweblogic.StdoutDebugEnabled=false" |
| 159 | + - name: USER_MEM_ARGS |
| 160 | + value: "-Xms64m -Xmx256m " |
| 161 | + volumes: |
| 162 | + - name: runtime-properties |
| 163 | + hostPath: |
| 164 | + path: "/scratch/weblogic-kubernetes-operator/kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/docker-images/OracleWebLogic/samples/12213-domain-home-in-image/properties/docker_run" |
| 165 | + volumeMounts: |
| 166 | + - name: runtime-properties |
| 167 | + mountPath: "/u01/oracle/properties" |
| 168 | + # clusters is used to configure the desired behavior for starting member servers of a cluster. |
| 169 | + # If you use this entry, then the rules will be applied to ALL servers that are members of the named clusters. |
| 170 | + clusters: |
| 171 | + cluster-1: |
| 172 | + desiredState: "RUNNING" |
| 173 | + replicas: 2 |
| 174 | + env: |
| 175 | + - name: JAVA_OPTIONS |
| 176 | + value: "-Dweblogic.StdoutDebugEnabled=false" |
| 177 | + - name: USER_MEM_ARGS |
| 178 | + value: "-Xms64m -Xmx256m " |
| 179 | + volumes: |
| 180 | + - name: runtime-properties |
| 181 | + hostPath: |
| 182 | + path: "/scratch/weblogic-kubernetes-operator/kubernetes/samples/scripts/create-weblogic-domain/domain-home-in-image/docker-images/OracleWebLogic/samples/12213-domain-home-in-image/properties/docker_run" |
| 183 | + volumeMounts: |
| 184 | + - name: runtime-properties |
| 185 | + mountPath: "/u01/oracle/properties" |
| 186 | + # The number of managed servers to start for unlisted clusters |
| 187 | + # replicas: 1 |
| 188 | +
|
| 189 | +``` |
| 190 | + |
| 191 | +### Verify the domain |
| 192 | + |
| 193 | +To confirm that the domain was created, use this command: |
| 194 | + |
| 195 | +``` |
| 196 | +kubectl describe domain DOMAINUID -n NAMESPACE |
| 197 | +``` |
| 198 | + |
| 199 | +Replace `DOMAINUID` with the `domainUID` and `NAMESPACE` with the actual namespace. |
| 200 | + |
| 201 | +Here is an example of the output of this command: |
| 202 | + |
| 203 | +``` |
| 204 | +$ kubectl describe domain domain1 |
| 205 | +Name: domain1 |
| 206 | +Namespace: default |
| 207 | +Labels: weblogic.domainName=base_domain |
| 208 | + weblogic.domainUID=domain1 |
| 209 | + weblogic.resourceVersion=domain-v2 |
| 210 | +Annotations: <none> |
| 211 | +API Version: weblogic.oracle/v1 |
| 212 | +Kind: Domain |
| 213 | +Metadata: |
| 214 | + Cluster Name: |
| 215 | + Creation Timestamp: 2018-10-31T12:59:15Z |
| 216 | + Generation: 0 |
| 217 | + Resource Version: 1314703 |
| 218 | + Self Link: /apis/weblogic.oracle/v1/namespaces/default/domains/domain1 |
| 219 | + UID: c52f5e11-dd0c-11e8-9238-fa163e855ac8 |
| 220 | +Spec: |
| 221 | + Admin Secret: |
| 222 | + Name: domain1-weblogic-credentials |
| 223 | + As Name: admin-server |
| 224 | + As Port: 7001 |
| 225 | + Cluster Startup: |
| 226 | + Cluster Name: cluster-1 |
| 227 | + Desired State: RUNNING |
| 228 | + Env: |
| 229 | + Name: JAVA_OPTIONS |
| 230 | + Value: -Dweblogic.StdoutDebugEnabled=false |
| 231 | + Name: USER_MEM_ARGS |
| 232 | + Value: -Xms64m -Xmx256m |
| 233 | + Replicas: 2 |
| 234 | + Clusters: |
| 235 | + Domain Home In Image: false |
| 236 | + Domain Name: base_domain |
| 237 | + Domain UID: domain1 |
| 238 | + Env: |
| 239 | + Export T 3 Channels: |
| 240 | + T3Channel |
| 241 | + Exported Network Access Points: |
| 242 | + Image: store/oracle/weblogic:12.2.1.3 |
| 243 | + Image Pull Policy: IfNotPresent |
| 244 | + Image Pull Secret: |
| 245 | + Liveness Probe: |
| 246 | + Managed Servers: |
| 247 | + Readiness Probe: |
| 248 | + Server Startup: |
| 249 | + Desired State: RUNNING |
| 250 | + Env: |
| 251 | + Name: JAVA_OPTIONS |
| 252 | + Value: -Dweblogic.StdoutDebugEnabled=false |
| 253 | + Name: USER_MEM_ARGS |
| 254 | + Value: -Xms64m -Xmx256m |
| 255 | + Node Port: 30701 |
| 256 | + Server Name: admin-server |
| 257 | + Startup Control: AUTO |
| 258 | + Storage: |
| 259 | + Predefined: |
| 260 | + Claim: domain1-weblogic-sample-pvc |
| 261 | +Status: |
| 262 | + Conditions: |
| 263 | + Last Transition Time: 2018-10-31T13:01:34.786Z |
| 264 | + Reason: ServersReady |
| 265 | + Status: True |
| 266 | + Type: Available |
| 267 | + Servers: |
| 268 | + Health: |
| 269 | + Activation Time: 2018-10-31T13:07:14.472Z |
| 270 | + Overall Health: ok |
| 271 | + Subsystems: |
| 272 | + Node Name: xxxxxxxx |
| 273 | + Server Name: admin-server |
| 274 | + State: RUNNING |
| 275 | + Cluster Name: cluster-1 |
| 276 | + Health: |
| 277 | + Activation Time: 2018-10-31T13:01:05.100Z |
| 278 | + Overall Health: ok |
| 279 | + Subsystems: |
| 280 | + Node Name: xxxxxxxx |
| 281 | + Server Name: managed-server1 |
| 282 | + State: RUNNING |
| 283 | + Cluster Name: cluster-1 |
| 284 | + Health: |
| 285 | + Activation Time: 2018-10-31T13:01:05.190Z |
| 286 | + Overall Health: ok |
| 287 | + Subsystems: |
| 288 | + Node Name: xxxxxxxx |
| 289 | + Server Name: managed-server2 |
| 290 | + State: RUNNING |
| 291 | + Start Time: 2018-10-31T12:59:15.244Z |
| 292 | +Events: <none> |
| 293 | +``` |
| 294 | + |
| 295 | +In the `Status` section of the output, the available servers and clusters are listed. Note that if this command is issued very soon after the script finishes, there may be no servers available yet, or perhaps only the Administration Server but no Managed Servers. The operator will start up the Administration Server first and wait for it to become ready before starting Managed Servers. |
| 296 | + |
| 297 | +### Verify pods |
| 298 | + |
| 299 | +The following command can be used to see the pods running the servers: |
| 300 | + |
| 301 | +``` |
| 302 | +kubectl get pods -n NAMESPACE |
| 303 | +``` |
| 304 | + |
| 305 | +Here is an example of the output of this command: |
| 306 | + |
| 307 | +``` |
| 308 | +$ kubectl get pods |
| 309 | +NAME READY STATUS RESTARTS AGE |
| 310 | +domain1-admin-server 1/1 Running 0 1m |
| 311 | +domain1-managed-server1 1/1 Running 0 8m |
| 312 | +domain1-managed-server2 1/1 Running 0 8m |
| 313 | +``` |
| 314 | + |
| 315 | +### Verify services |
| 316 | + |
| 317 | +The following command can be used to see the services for the domain: |
| 318 | + |
| 319 | +``` |
| 320 | +kubectl get services -n NAMESPACE |
| 321 | +``` |
| 322 | + |
| 323 | +Here is an example of the output of this command: |
| 324 | +``` |
| 325 | +$ kubectl get services |
| 326 | +NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE |
| 327 | +domain1-admin-server NodePort 10.96.206.134 <none> 7001:30701/TCP 23m |
| 328 | +domain1-admin-server-extchannel-t3channel NodePort 10.107.164.241 <none> 30012:30012/TCP 22m |
| 329 | +domain1-cluster-cluster-1 ClusterIP 10.109.133.168 <none> 8001/TCP 22m |
| 330 | +domain1-managed-server1 ClusterIP None <none> 8001/TCP 22m |
| 331 | +domain1-managed-server2 ClusterIP None <none> 8001/TCP 22m |
| 332 | +``` |
| 333 | + |
| 334 | +## Delete domain |
| 335 | + |
| 336 | +Th generated YAML file in the `/path/to/weblogic-operator-output-directory/weblogic-domains/<domainUID>` directory can also be used to delete the Kubernetes resource. The following command can be used to delete domain: |
| 337 | + |
| 338 | +``` |
| 339 | +$ kubectl delete -f domain.yaml |
| 340 | +
|
| 341 | +``` |
0 commit comments