How to deploy IBM API Connect using command-line
Written in collaboration with Rengan Sundararaman
Introduction
After you install Cloud Pak for Integration, you get a nice Platform Navigator, where you can deploy the Cloud Pak for Integration components. From there, you can click the “Add new instance” button, fill the parameters, and deploy the component.
However, there are many circumstances where you need to do through the command line. Imagine, for example, deploying API Connect as part of your Continuous Delivery process.
In this blog, I will describe the steps required to deploy API Connect through the command line, then we will provide an automated script to deploy API Connect with a single command.
Step-by-Step Procedure
In this tutorial, I will deploy API Connect to the apic
project. To make life easier, let’s define the following environment variables:
export PROJECT=apic
export ICP_PASSWORD=<your ICP password>
export NAME=<name of the API Connect instance>
Log on to your OpenShift cluster
The first thing I need to do is to log on to OpenShift, using oc login
Obtain ICP Master URL
Run the following command to set the MASTER_URL environment variable:
export MASTER_URL=https://$(oc get route icp-console -n kube-system -o jsonpath='{@.status.ingress[0].host}')
You can check the result by running echo $MASTER_URL
Configure Helm CLI
Next, I need to configure the Helm CLI. Run the following command:
cloudctl login -a $MASTER_URL -u admin -p $ICP_PASSWORD -n kube-system --skip-ssl-validation
Re-login to OpenShift cluster
After configuring the Helm CLI, we need to re-login to the OpenShift cluster, by running oc login
again.
You can check that the oc and helm CLIs are properly working, by running the following commands:
oc status
helm list --tls
Create the Role Binding
Now, that I configured the CLIs, I can proceed to create the necessary artifacts.
The first step is to create a role binding, granting the project’s service account to use HostPath for persistent and to deploy as any user ID:
oc -n $PROJECT create rolebinding apic-security-policy \
--clusterrole=ibm-anyuid-hostpath-scc \
--group=system:serviceaccounts:$PROJECT
Create the TLS Secret
Next, we need to create the TLS Secret, by running the following command:
oc create secret generic helm-tls-secret \
--from-file=cert.pem=$HOME/.helm/cert.pem \
--from-file=ca.pem=$HOME/.helm/ca.pem \
--from-file=key.pem=$HOME/.helm/key.pem
Obtain the ICP Proxy route
I now need to obtain the route for the ICP proxy:
export ROUTE=$(oc get route icp-proxy -n kube-system -o jsonpath='{@.status.ingress[0].host}')
Create the Helm Values file
Ok, I am almost there. We are at the final step before deploying is to configure the Helm values file.
This file allows the set many parameters for the API Connect, but for this tutorial, I will make many assumptions.
I prepared a simple values.yaml
template that needs to be configured with the ICP Proxy route information defined above.
Run the following command to generate the values file:
curl https://raw.githubusercontent.com/patrocinio/cloud-paks-resilience/master/Integration/values.yaml.template | sed s/\$ROUTE/$ROUTE/g > /tmp/values.yaml
Deploy the Helm chart
I am finally ready to deploy the API Connect Helm chart.
Run the following command:
helm install https://github.com/IBM/charts/raw/master/repo/entitled/ibm-apiconnect-icp4i-prod-1.0.3.tgz \
--name $NAME --tls -f /tmp/values.yaml
And voilà.
Automating the process to deploy API Connect
The process below was straightforward, but incurred in many steps. I promised to give a simple way to deploy API Connect, so let’s look a script that does it all.
Well, you still need to clone a github repository:
git clone https://github.com/patrocinio/cloud-paks-resilience.git
cd cloud-paks-resilience/Integration
Assuming that you have configured the oc and Helm CLIs, you can simply run the following script:
./deploy_apic.sh <API Connect instance name>
Done! With a single command, you can deploy an instance of API Connect
Conclusion
In this blog, I showed how to deploy an instance of API Connect, as part of the Cloud Pak for Integration.
Bring your plan to the IBM Garage.
Are you ready to learn more about working with the IBM Garage? We’re here to help. Contact us today to schedule time to speak with a Garage expert about your next big idea. Learn about our IBM Garage Method, the design, development and startup communities we work in, and the deep expertise and capabilities we bring to the table.
Schedule a no-charge visit with the IBM Garage.