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.
- Log in to IBM Cloud.
- In the top left corner, click the three horizontal lines to open the IBM Cloud menu.
- Select Kubernetes from the menu.
- In the Registry tab, click the Namespaces card.
- Hit the Create + button in the right side.
- In the Create namespace screen, use your
username
as name. - Click the Create button.
- Log in to IBM Cloud.
- Click
username
-python-microservice in the Apps link on the Resource summary panel. - Click Disconnect toolchain in the top right corner of the Deployment Automation card to remove the old Cloud Foundry-based toolchain.
- Then click the Deploy your app button to re-enable the Continuous Delivery feature.
- In the Choose a deployment environment panel, pick Deploy to Kubernetes and hit Next.
- In the Configure toolchain panel, name the toolchain as
username
-python-microservice-k8s (wherek8s
refers to "Kubernetes") and click Create. - In the Deployment Automation card, click the name of your toolchain.
- On the top right, click Add a Tool and choose GitHub from the catalog.
- Authorise access from IBM Cloud to your GitHub account by clicking the Authorize button.
- Under Repository type, choose Link from the menu.
- Select the
username
-python-microservice repository from the Repository URL menu. - Make sure the Enable GitHub Issues and Track deployment of code changes boxes are checked.
- Click Create Integration.
- Log in to IBM Cloud.
- Click
username
-python-microservice in the Apps link on the Resource summary panel. - In the Deployment Automation card, click the name of your Delivery Pipeline.
- In the next screen, click the gear icon in the Build Stage card and then Configure Stage.
- In the Input tab, choose the option in Git repository that leads to Github as Git URL.
- Save your changes and run the Build Stage by clicking the
▶️ icon.
- Log in to IBM Cloud.
- Click
username
-python-microservice in the Apps link on the Resource summary panel. - In the Deployment Automation card, click the name of your Delivery Pipeline.
- Track the progress of your latest commit from the Build Stage to the Deploy Stage.
- Click the View logs and history link in the Deploy Stage card.
- After a successful deploy, at the very bottom of the page, you will find a link like http://IP_ADRESS:PORT.
- Click the link and add
/apidocs/
to the URL in order to open the Swagger API documentation.
- Open Visual Studio Code and summon the Command Palette with
- Type
terminal
and choose View: Toggle Integrated Terminal. - In the terminal window, issue
ibmcloud login --sso
and follow the on-screen instructions to log in to IBM Cloud. - Execute
ibmcloud ks init
, thenibmcloud cr login
. If the second command fails, make sure Docker is running locally. - Configure your Kubernetes cluster by executing the command
ibmcloud ks cluster config --cluster <username>-cluster
- Create a Kubernetes namespace.
kubectl create namespace <username>
- Configure your
kubectl
environment.kubectl config set-context <username>-cluster --cluster=<username>-cluster --namespace=<username>
- 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 -
- Take note of the Repository URL and image Tag number in the output of
ibmcloud cr images
. - 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
- Take note of the Public IP from the output of
ibmcloud ks workers --cluster <username>-cluster
. - Take note of the secondary Port number (after the
:
) in the output ofkubectl get all
. - Open a browser window and access
<http://PUBLIC_IP:PORT/apidocs/>
.