Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Latest commit

 

History

History
85 lines (74 loc) · 5.47 KB

4-CONTAINERISE.md

File metadata and controls

85 lines (74 loc) · 5.47 KB

Containerising the Python application

In this section, you will replace the Cloud Foundry-based delivery pipeline by one that uses Kubernetes as deployment strategy. You will create a configure the new Kubernetes-based pipeline and, optionally, learn how to perform the Kubernetes deployment manually.

Setting up a private registry namespace

  1. Log in to IBM Cloud.
  2. In the top left corner, click the three horizontal lines to open the IBM Cloud menu.
  3. Select Kubernetes from the menu.
  4. In the Registry tab, click the Namespaces card.
  5. Hit the Create + button in the right side.
  6. In the Create namespace screen, use your username as name.
  7. Click the Create button.

Creating a new Kubernetes-based toolchain

  1. Log in to IBM Cloud.
  2. Click username-python-microservice in the Apps link on the Resource summary panel.
  3. Click Disconnect toolchain in the top right corner of the Deployment Automation card to remove the old Cloud Foundry-based toolchain.
  4. Then click the Deploy your app button to re-enable the Continuous Delivery feature.
  5. In the Choose a deployment environment panel, pick Deploy to Kubernetes and hit Next.
  6. In the Configure toolchain panel, name the toolchain as username-python-microservice-k8s (where k8s refers to "Kubernetes") and click Create.
  7. In the Deployment Automation card, click the name of your toolchain.
  8. On the top right, click Add a Tool and choose GitHub from the catalog.
  9. Authorise access from IBM Cloud to your GitHub account by clicking the Authorize button.
  10. Under Repository type, choose Link from the menu.
  11. Select the username-python-microservice repository from the Repository URL menu.
  12. Make sure the Enable GitHub Issues and Track deployment of code changes boxes are checked.
  13. Click Create Integration.

Deploying a container with Continuous Delivery Pipeline

  1. Log in to IBM Cloud.
  2. Click username-python-microservice in the Apps link on the Resource summary panel.
  3. In the Deployment Automation card, click the name of your Delivery Pipeline.
  4. In the next screen, click the gear icon in the Build Stage card and then Configure Stage.
  5. In the Input tab, choose the option in Git repository that leads to Github as Git URL.
  6. Save your changes and run the Build Stage by clicking the ▶️ icon. k8s_build_stages

Accessing the containerised application

  1. Log in to IBM Cloud.
  2. Click username-python-microservice in the Apps link on the Resource summary panel.
  3. In the Deployment Automation card, click the name of your Delivery Pipeline.
  4. Track the progress of your latest commit from the Build Stage to the Deploy Stage.
  5. Click the View logs and history link in the Deploy Stage card.
  6. After a successful deploy, at the very bottom of the page, you will find a link like http://IP_ADRESS:PORT.
  7. Click the link and add /apidocs/ to the URL in order to open the Swagger API documentation.

Deploying a container manually using the command-line

  1. Open Visual Studio Code and summon the Command Palette with
  2. Type terminal and choose View: Toggle Integrated Terminal.
  3. In the terminal window, issue ibmcloud login --sso and follow the on-screen instructions to log in to IBM Cloud.
  4. Execute ibmcloud ks init, then ibmcloud cr login. If the second command fails, make sure Docker is running locally.
  5. Configure your Kubernetes cluster by executing the command
    ibmcloud ks cluster config --cluster <username>-cluster
  6. Create a Kubernetes namespace.
    kubectl create namespace <username>
  7. Configure your kubectl environment.
    kubectl config set-context <username>-cluster --cluster=<username>-cluster --namespace=<username>
  8. Export your image registry secrets.
    kubectl get secret bluemix-default-secret-regional -n default -o yaml | sed 's/default/<username>/g' | kubectl create -f -
    kubectl get secret bluemix-default-secret-international -n default -o yaml | sed 's/default/<username>/g' | kubectl create -f -
  9. Take note of the Repository URL and image Tag number in the output of ibmcloud cr images.
  10. Create a Pod based on your image and expose it with a NodePort service.
    kubectl run <username>-python-microservice --image=<repository>:<tag> --restart=Never --image-pull-policy=Always --overrides='{ "apiVersion": "v1", "spec": { "imagePullSecrets": [{"name": "bluemix-<username>-secret-regional"}] } }'
    kubectl expose pod <username>-python-microservice --port=3000 --type=NodePort --name=<username>-python-microservice
  11. Take note of the Public IP from the output of ibmcloud ks workers --cluster <username>-cluster.
  12. Take note of the secondary Port number (after the :) in the output of kubectl get all.
  13. Open a browser window and access <http://PUBLIC_IP:PORT/apidocs/>.