This TNO solution is primarily hosted within Openshift. Everything relevant and required by the solution is capture as "Infrastructure as Code" so that it is easily setup, configured, built, and deployed. You can find all templates files and instructions for Openshift in this folder.
The Exchange Lab has an app that provides a way to request a new product, or provision more resource quotas here https://registry.developer.gov.bc.ca/dashboard
There are a number of helpful tips here - openshift.tips
The following command will extract parameters from the template.
This will provide you a list of all the parameters, which you can extract to create a parameter file.
When creating a parameter file, use .env
files so they are not committed to the source code repository.
oc process -f ${pathToFile:-build.yaml} --parameters=true
The following command will process a template, apply configured parameters and create the objects in the template within Openshift. This will also save the template within Openshift.
oc process -f ${pathToFile:-build.yaml} --param-file=${pathToFile:-build.dev.env} | oc create --save-config=true -f -
The following command will delete all objects in the template.
oc process -f ${pathToFile:-build.yaml} --param-file=${pathToFile:-build.dev.env} | oc delete -f -
The following command will replace all objects in the template, apply configured parameters and create the objects in the template within Openshift.
oc process -f ${pathToFile:-build.yaml} --param-file=${pathToFile:-build.dev.env} | oc replace --save-config=true -f -
The following command will update all objects in the template, apply configured parameters and update the template within Openshift.
oc process -f ${pathToFile:-build.yaml} --param-file=${pathToFile:-build.dev.env} | oc apply -f -
For Services, the process is slightly different. Use apply
to patch values or replace
to replace. Note that apply
will not remove existing values if you change names.
oc kustomize ${pathToEnvironmentFolder} | oc [apply|replace] -f -
The following command will port forward the specified container so that you can communicate with the pod directly from your computer.
# Get the pod name so you can reference it.
oc get pods -n ${project:-9b301c-dev}
oc port-forward $podName ${localPort:-22222}:${containerPort:-5432}
By default security is Zero Trust. Which means nothing can communicate. For a basic setup where TOOLS provides images the following projects need to have access DEV, TEST, and PROD.
Enable the Service Account to pull images from external sources.
oc policy add-role-to-user system:image-puller system:serviceaccount:9b301c-dev:default -n 9b301c-tools
oc policy add-role-to-user system:image-puller system:serviceaccount:9b301c-test:default -n 9b301c-tools
oc policy add-role-to-user system:image-puller system:serviceaccount:9b301c-prod:default -n 9b301c-tools
# Or apply to the tno account
oc policy add-role-to-user system:image-puller system:tno:9b301c-prod:default -n 9b301c-tools
# Or apply this to all serviceaccounts
oc policy add-role-to-group system:image-puller system:serviceaccounts:9b301c-prod -n 9b301c-tools
There are additional default configurations in the ./templates/network-policy
folder.
These should be applied to each project.
oc process -f ./network-policy/default.yaml --param-file=${pathToFile:default.dev.env} | oc create --save-config=true -f -
oc process -f ./network-policy/default.yaml --param-file=${pathToFile:default.test.env} | oc create --save-config=true -f -
oc process -f ./network-policy/default.yaml --param-file=${pathToFile:default.prod.env} | oc create --save-config=true -f -
oc process -f ./network-policy/default.yaml --param-file=${pathToFile:default.tools.env} | oc create --save-config=true -f -
If you need to find images hosted in a image registry within Openshift.
# List all images in bcgov namespace
oc -n bcgov get is
# Search images
oc -n bcgov get imagestreamtag | grep $imageName
Some Redhat images are only accessible if they are first imported through Openshift.
oc import-image postgresql-13 --from=registry.redhat.io/rhel8/postgresql-13 --confirm -n 9b301c-tools
Login first.
# Login with Docker (insecure)
docker login -u $(oc whoami) -p $(oc whoami -t) image-registry.apps.silver.devops.gov.bc.ca
# Or login securely
oc whoami -t | docker login -u $(oc whoami) --password-stdin image-registry.apps.silver.devops.gov.bc.ca
If you have a local image you can push up to Openshift.
# List images
docker images
# Tag the image you want to push
docker tag $imageName:$tag image-registry.apps.silver.devops.gov.bc.ca/9b301c-tools/$imageName:$tag
# Push to image registry in Openshift
docker push image-registry.apps.silver.devops.gov.bc.ca/9b301c-tools/$imageName:$tag
If you want to pull down an image from Openshift.
# List image
oc get is -n 9b301c-tools
# Pull image from Openshift
docker pull image-registry.apps.silver.devops.gov.bc.ca/9b301c-tools/$imageName:$tag
Sometimes you may need to confirm you container can communicate with the internet.
timeout 5 bash -c "</dev/tcp/google.com/443"; echo $?
If you need to update the resource requirements of pods you can do this without editing their templates.
oc set resources dc/${DeployConfig.name} --requests=cpu=50m,memory=50Mi --limits=cpu=500m,memory=500Mi
Sometimes it's a pain to remember the random names of the project, it's nice to use a command that extracts it.
# Extract the random characters of the project namespace.
project=$(oc project --short); project=${project//-[a-z]*/}; echo $project
# Change the current environment
oc project $project-tools
You can use the CLI to copy local files to or from a remote directory in a container. More information here
oc rsync <source> <destination> [-c <container>]
# Copy to pod
oc rsync /home/user/source devpod1234:/src
# Copy from pod
oc rsync devpod1234:/src /home/user/source
If you need to create a pod that mounts a PVC first.
oc run some-pod --overrides='{"spec": {"containers": [{"command": ["/bin/bash", "-c", "trap : TERM INT; sleep infinity & wait"], "image": "registry.access.redhat.com/rhel7/rhel:latest", "name": "some-pod", "volumeMounts": [{"mountPath": "/data", "name": "some-data"}]}], "volumes": [{"name": "some-data", "persistentVolumeClaim": {"claimName": "test-file"}}]}}' --image=dummy --restart=Never
(Documentat)[https://docs.openshift.com/container-platform/3.11/dev_guide/ssh_environment.html]
oc rsh <pod>
for pod in $(oc get pods | grep Error | awk '{print $1}'); do oc delete pod --grace-period=1 ${pod}; done
oc get pods api-0 -o jsonpath="{..imageID}"