Skip to main content

Change a Replicated License in a Kotsadm application

note

These instructions are not relevant to airgapped installations as the kotsadm console allows upload of a new license file at any time.

It's not typical to change a license for a deployed instance of CredoAI as license alterations are performed remotely and synchronized to the kotsadm console.

However in some cases it may be desired to use a new license for a particular instance especially if you would like to have different environments track distinct CredoAI distribution channels (ie Stable and Beta).

The following instructions give some suggestions around the usage of the kots cli and the application lifecycle management.

script

This script sets up a command replicated-kots.sh that supports save, restore, remove and backup subcommands.

tip

To use the script, copy the content a file replicated.kots.sh and chmod +x replicated-kots.sh.

#!/usr/bin/env bash

REPLICATED_APP=credoai
REPLICATED_KOTS_LOCAL_DIR=${REPLICATED_KOTS_LOCAL_DIR:"replicated"}
REPLICATED_LICENSE=""
CONFIG_PATH=""
NS="$REPLICATED_APP"

function usage() {
echo "Usage: $0 {save|restore|remove|bootstrap} [--namespace <namespace>] [--license <license.yaml>] [--config <kots-config.yaml>]"
}

function save() {
TS=$(TZ=UTC date +%Y%m%dZ%H%M%S)
echo "Snapshotting app ${REPLICATED_APP} in namespace ${NS} with timestamp ${TS}..."

if [[ -z $CONFIG_PATH ]]; then
CONFIG_PATH="${REPLICATED_KOTS_LOCAL_DIR}/${NS}/kots-config_${TS}.yaml"
echo "No config supplied -- using constructed path ${CONFIG_PATH}"
fi

kubectl kots get config \
"$REPLICATED_APP" \
-n "$NS" \
--decrypt \
"${EXTRA_ARGS[@]}" \
> "$CONFIG_PATH"

echo "Saved to config ${CONFIG_PATH}"
}

function remove() {
echo "Removing app ${REPLICATED_APP} in namespace ${NS} from kotsadm..."

kubectl kots remove \
"$REPLICATED_APP" \
-n "$NS" \
--force \
"${EXTRA_ARGS[@]}"

echo "Removed"
}

function restore() {
echo "Restoring app ${REPLICATED_APP} in namespace ${NS} with config ${CONFIG_PATH}..."

kubectl kots set config \
"$REPLICATED_APP" \
-n "$NS" \
--config-file "$CONFIG_PATH" \
"${EXTRA_ARGS[@]}"

echo "Ready to deploy"
}

function bootstrap() {
echo "Bootstrapping app ${REPLICATED_APP} in namespace ${NS} with license ${REPLICATED_LICENSE}..."

if [[ -z $REPLICATED_LICENSE ]]; then
REPLICATED_LICENSE="${REPLICATED_KOTS_LOCAL_DIR}/${NS}/license.yaml"
echo "No license supplied -- using constructed path ${REPLICATED_LICENSE}"
fi

kubectl kots install \
"$REPLICATED_APP" \
-n "$NS" \
--disable-image-push \
--airgap=false \
--license-file="$REPLICATED_LICENSE" \
--shared-password "$REPLICATED_KOTS_PASSWORD" \
--no-port-forward \
"${EXTRA_ARGS[@]}"

echo "Ready to configure"
}

if [[ $# -eq 0 ]]; then
usage
exit 1
fi

EXTRA_ARGS=()
while [ $# -gt 0 ]; do
case $1 in
bootstrap | help | remove | restore | save)
CMD=$1
shift
;;
--help)
usage
exit 0
;;
-c | --config)
shift
CONFIG_PATH=$1
shift
;;
-l | --license)
shift
REPLICATED_LICENSE=$1
shift
;;
-n | --namespace)
shift
NS=$1
shift
;;
*)
EXTRA_ARGS+=("$1")
shift
;;
esac
done
echo "Passed extra args: "
echo "${EXTRA_ARGS[@]}"

case "$CMD" in
bootstrap)
bootstrap
;;
remove)
remove
;;
restore)
restore
;;
save)
save
;;
esac

script usage

note

The following commands assume the CredoAI application was deployed to the credoai namespace. Use the --namespace flag if installed to a different namespace.

tip

The command support additional arguments to be passed to the replicated cli.

Make a backup

./replicated-kots.sh save --config the-kots-config.yaml

Remove the app

./replicated-kots.sh remove

Bootstrap the app with the new license and saved configuration

tip

This command also restores the CredoAI application's config. It is not necessary to run the restore command.

./replicated-kots.sh bootstrap --license the-new-license.yaml --config the-kots-config.yaml

Restore the app (optional)

tip

This command is not necessary for the license swap but may be useful as part of a backup strategy.

./replicated-kots.sh restore --config the-kots-config.yaml