As enterprises move workloads to the cloud, transparency and visibility across development and operations (DevOps) teams are really important. The real power of the Slack messaging platform is to help teams collaborate and coordinate their work no matter where they are located, in the field office, at home, or anywhere around the globe. This tutorial shows you how to set up a toolchain of IBM Cloud services that uses a continuous integration and continuous delivery (CI/CD) stack to maintain and deploy applications running on a Kubernetes cluster. Then, it shows how you can enhance the collaboration experience within your DevOps team by integrating the toolchain with the Slack platform so your Slack channel receives notifications about deployment activities.
You need the following tools to complete the steps in this tutorial:
- IBM Cloud account.
- Access to the IBM Cloud Kubernetes Service to create a Kubernetes cluster. If needed, you can create one free cluster for 30 days to get familiar with Kubernetes capabilities.
- Slack workspace.
- Visual Studio Code or another integrated development environment (IDE) for local development.
- A GitHub account and some knowledge of Git commands.
It will take you less than one hour to complete this tutorial.
- Fork and clone the GitHub repository
- Create a Kubernetes cluster
- Create the container registry
- Configure a toolchain
- Verify the application is running
- Activate the Slack API
- Integrate your Slack app with your toolchain
- Change the toolchain and check updates on Slack
Step 1. Fork and clone the GitHub repository
- Open the GitHub repository that contains the sample code for this tutorial.
- Click Fork from the menu bar to copy the repository into your GitHub account. You will use the URL of your forked repository in Step 4.
- Open your terminal and change your directory by using the
cd downloadscommand (or any other directory in which you want to clone the project).
- Run the
git clone https://github.com/IBM/CICD-Kubernetes-Slack.gitcommand.
- Move into the cloned folder and run the
npm installcommand to install the dependencies.
- Run the
node app.jscommand to check that the application runs successfully on you local device.
Note: The project contains the Dockerfile and deployment files that you use in the next few steps, so please go through the files. This tutorial does not focus on how to write these two files.
Step 2. Create a Kubernetes cluster
- Log into your IBM Cloud account and navigate to the Kubernetes Cluster page.
Create a Kubernetes cluster. If you need assistance, refer to the steps in the Getting started with IBM Cloud Kubernetes Service documentation.
It may take 10 to 15 minutes for your Kubernetes cluster to provision.
Step 3. Create the container registry
- Go to the Container Registry page within IBM Cloud.
- Click the Create button.
- Within the Location drop box, select the region that is closest to you geographically.
- Click the Namespaces tab.
- Click Create.
- In the Create namespace pane, enter a unique name for your registry within the Name field.
- Click Create.
Note: Although you could skip this step and directly integrate the container registry within Step 4, it could cause an error if your registry name is not unique.
Step 4. Configure a toolchain
Toolchains provide an integrated set of tools to build, deploy, and manage your apps. By creating a toolchain on IBM Cloud, you can develop and deploy an application securely into a Kubernetes cluster managed by the IBM Cloud Kubernetes Service. The toolchain includes Vulnerability Advisor to provide a secure container.
After you create the toolchain in this step and push the changes to your repository, the delivery pipeline will automatically build and deploy the code. Learn more about creating toolchains on IBM Cloud.
Perform the following tasks:
- Go to the Create a Toolchain dashboard within IBM Cloud.
- There are many ready-made toolchains are available on the dashboard. Select Develop a Kubernetes app.
- Enter any name you want within the Toolchain Name field.
- In the Select Region field, choose the same location as the one you chose in Step 3.
- In the Select a source provider field, choose Git Repos and Issue Tracking.
- Within the Tool Integrations section, in the Source repository URL field, enter the URL of the forked repository that you created in Step 1.
- Click the Delivery Pipeline tab.
- In the App name field, enter
- In the IBM Cloud API key field, click the New button.
- In the Create a new API key with full access window, select OK.
- In the Container registry region and Cluster region fields, select the region where you created your services earlier.
- Click the Create button.
After the Delivery Pipeline status box indicates that it is configured successfully, click it to open the Delivery Pipeline status page.
The screen capture of the Delivery Pipeline page shows the three pipeline stages:
- Build: If a
manifest.ymlfile exists in the root folder, it is used to determine which buildpack to use.
- Containerize: This stage checks for the Dockerfile in your root folder, creates a container registry after the image is successfully built, and deploys the image in the registry. This stage also checks for any vulnerabilities in the image, and if there are any, then images with high warnings will not deploy.
- Deploy: This stage checks for cluster readiness and namespace existence, configures the cluster namespace, updates the
deployment.ymlmanifest file, and grants access to the private image registry.
- Build: If a
Note: The screen capture image displays a warning because we did not activate the SSL certificate.
Step 5. Verify the application is running
- Within the Deploy stage, click View logs and history.
- Select Deploy to Kubernetes.
- Scroll to the end of the logs, until you reach
VIEW THE APPLICATION AT:followed by a URL.
Open your browser and run the URL to check whether the application is running.
Now you will verify if the services are running on your Kubernetes cluster.
- Go to the Resource list in IBM Cloud.
- Expand Cluster and click on the Kubernetes cluster service that you created in Step 2.
- Within your cluster service page, select Kubernetes dashboard from the menu bar.
- Within the side panel of the Kubernetes dashboard, click Namespaces.
- Select default from the Namespaces list.
- Check the services running as
Step 6. Activate the Slack API
If you do not already have a Slack account, create one before starting the following tasks to activate the Slack API.
- Within your browser, go to https://api.slack.com/apps.
- Click Create an App.
- Within the Create a Slack App window, enter
IBM Toolchainin the App Name field.
- In the Development Slack Workspace drop down list, select the workspace that you identified or created to fulfill the Prerequisites for this tutorial.
- Click Create App. After your app is created, you will be redirected to the settings page for your new app.
- Select Incoming Webhooks.
- Set Activate Incoming Webhooks to On.
- Click Add New Webhook to Workspace.
- Pick a channel from the list that you want the app to post notifications to.
- Click Allow.
- Back on the Incoming Webhooks page, there is a new entry within the Webhook URL section for the channel you selected. Click the Copy button to save the URL for an upcoming task.
Step 7. Integrate your Slack app with your toolchain
Now that your Slack app is set up, you can integrate it with your toolchain in IBM Cloud.
- Go to the Toolchains dashboard within IBM Cloud.
- In the Location list, choose the region where you created your toolchain in Step 4.
- Select your toolchain from the list.
- On you toolchain overview page, click the Add tool button.
Slackin the search box and click the Slack integration option that appears.
- On the Configure Slack page, paste the webhook URL that you copied at the end of Step 6 into the Slack webhook field.
- Within the Slack channel field, enter the name of the channel that you selected in Step 6 to post notifications to.
- In the Slack team name field, enter the name of your Slack team. (To find your team name, open your Slack workspace, expand your workspace name located in the side panel, and copy the word or phrase that appears before
Click the Create Integration button. Your toolchain overview page will now display your Slack integration within a Culture section of the pipeline.
Open your Slack workspace. Inside the configured channel will be a message stating that your Slack service has been bound to your toolchain.
Step 8. Change the toolchain and check updates on Slack
- From your toolchain overview page, click the Delivery Pipeline status box to open the Delivery Pipeline status page.
- Within the Deploy stage, click the Run Stage icon.
The stage will start running and verification messages will appear in your Slack workspace channel. In a real world scenario, everyone on your team would have better visualization of the project changes through these types of automated deployment messages.
In this tutorial, you learned how to work with toolchains to manage applications running on a Kubernetes cluster with automated stages that replace the manual interaction of development and operations teams. In addition, this tutorial demonstrated how the Slack platform can enhance DevOps collaboration by integrating it with an IBM Cloud toolchain to verify executions performed by a specific role. Teams could use DevOps toolchains for multi-staging strategies as part of their best practices. For example, before deploying a complete workload to a production Kubernetes cluster, it could be deployed in the test environment stage and not affect the production environment if there are any failures.