A simple script to start/stop/scale a WebLogic Server cluster running on k8s under WebLogic Kubernetes Operator

WebLogic Kubernetes Operator provides capabilities to create and deploy different types of WebLogic Domains (basic, JRE, RestrictedJRF, SOA, …) on k8s.

One of the built artifacts produced during the cluster setup is a yaml with stuff related to the domain resource, which is the construct provided by the operator for k8s to “understand” the concept of a WebLogic Domain.

The following script can be utilised for starting, stoping or scaling up and down the cluster, let’s see.

Step1: get the domain.yaml file, make a couple of changes

Locate the serverStartPolicy entry and replace the default value (“IF_NEEDED”) by the string SERVERSTARTPOLICY

Locate the replicas entry and replace by the string REPLICAS

# Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
# serverStartPolicy legal values are "NEVER", "IF_NEEDED", or "ADMIN_ONLY"
# This determines which WebLogic Servers the Operator will start up when it discovers this Domain
# - "NEVER" will not start any server in the domain
# - "ADMIN_ONLY" will start up only the administration server (no managed servers will be started)
# - "IF_NEEDED" will start all non-clustered servers, including the administration server and clustered servers up to the replica count
serverStartState: "RUNNING"
replicas: REPLICAS
# The number of managed servers to start for unlisted clusters
# replicas: 1

Step2: put domain yaml it in a git repo or in some place reachable by the script

Typically you can put the file in a git repo that contains the stuff you utilised to create the domain…

Step3: Get the script and run it in a shell configured to run kubectl against a k8s cluster

# assuming we have the domain.yaml file in this local directory
wget https://raw.githubusercontent.com/javiermugueta/rawcontent/master/wlsk8sctl
chmod 700 wlsk8sctl
# see instructions in the script itself
./wlsk8sctl -r=2 -o=STOP -y=domain.yaml
./wlsk8sctl -r=2 -o=START -y=domain.yaml
./wlsk8sctl -r=5 -o=START -y=domain.yaml

Step4(optional): Configure it in DevCS

Create a couple of build jobs Start and stop) and first set the git repo in which you have the domain.yaml file (modified) and probably other domain creation stuff:

Create a step as follows:

# kubeconfig setup from parameters
mkdir -p ~/.kube
oci ce cluster create-kubeconfig --cluster-id $OKE_CLUSTER_ID --file ~/.kube/config --region $REGION
export KUBECONFIG=~/.kube/config
# set namespace from parameters
kubectl config set-context --current --namespace=$NAMESPACE
# r should be set to the size of the clsuter
./wlsk8sctl -r=2 -o=START -y=domain.yaml
kubectl get po

Set the parameters or environment variables:

Finally, test it:

Please note that if you want to scale your cluster to, for example 5 pods, you can do this way:

./wlsk8sctl -r=5 -o=START -y=domain.yaml

That’s all for today, hope it helps and please stay home! 😉

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.