Building a docker image, pushing to OCIR and deploying to OKE with DevCS


OCIR=Oracle Cloud Infrastrure Registry

OKE=Oracle Kubernetes Engine

DevCS=Developer Cloud Service

Step 1: Create a new git repo or clon one existing with the code for building the image

Step2: Create a new job

Step3: Set the git repo

Step4: Add docker login step

The purpose is to login to the OCIR (OCI Registry). User is an OCI user, password is a token created for the user

Step5: Add docker build step

Here we build the docker image, is like executing docker build -t .

Step6: Add docker push step

Now we push the built image to OCIR

Step7: Add OCI Cli step

This is needed for the next step

Step8: Add unix shell step

This is aimed to execute kubectl stuff

# 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
echo $KUBECONFIG
# set namespace from parameters
kubectl config set-context --current --namespace=$NAMESPACE
# ocirsecret is utilized in panaweb.yaml to pull the docker image, create the first time only
kubectl create secret docker-registry ocirsecret --docker-username=fr....3/dev --docker-password="godblesswe'll" --docker-server=fra.ocir.io
# deploy yaml
kubectl apply -f panawebdesa.yaml
# deleting for forcing recreation
kubectl delete pods --selector=app=panaweb
# just a check, it will be logged in job output
kubectl get po
kubectl get svc

Step9: Add environment variables

These variables are utilised in the shell script created in the previous step

Step final: Execute the job

Execute the job and verify the execution in the log

Enjoy 🙂

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 )

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.