DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • How To Integrate Microsoft Team With Cypress Cloud
  • Top 10 Pillars of Zero Trust Networks
  • Using Render Log Streams to Log to Papertrail
  • Merge GraphQL Schemas Using Apollo Server and Koa

Trending

  • How To Integrate Microsoft Team With Cypress Cloud
  • Top 10 Pillars of Zero Trust Networks
  • Using Render Log Streams to Log to Papertrail
  • Merge GraphQL Schemas Using Apollo Server and Koa
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Running SonarQube in IBM Kubernetes Service (IKS) on IBM Cloud

Running SonarQube in IBM Kubernetes Service (IKS) on IBM Cloud

Learn how to make use of SonarQube, an automatic code review tool to ensure code quality is maintained.

Deepak Rai user avatar by
Deepak Rai
·
Sep. 23, 20 · Tutorial
Like (1)
Save
Tweet
Share
2.96K Views

Join the DZone community and get the full member experience.

Join For Free

Introduction

SonarQube empowers all developers to write cleaner and safer code. Catch bugs and vulnerabilities in your app, with thousands of automated Static Code Analysis rules. This will only make sure your code is as per the industry standards and you can rest assured there is comprehensive testing done with this.

This article enables you to quickly setup a community version of SonarQube in IBM Kubernetes service (IKS) on IBM Cloud. In this tutorial, you learn:

  1. Provisioning of a Kubernetes cluster in IBM Cloud and installing the required tools
  2. Installing SonarQube
  3. Launching the SonarQube dashboard

Prerequistes

  1. An IBM Cloud account
  2. Local machine with any OS ( I am using mac in this setup)

Deployment Setup

IBM Cloud UI

Log in to IBM Cloud ( https://cloud.ibm.com ). Go to Catalog, under services you can find Kubernetes service.

In this demo, I have used the Kubernetes 1.16.14 (Stable) version in a classic infrastructure in a single zone region. Once you choose the version, select Geography ( Asia Pacific), Availability (Single Zone), Worker Zone (Chennai 01) 

The worker node size used in this setup was 4 vCPUs and 16  GB Memory with 1 worker node per zone.

The master service endpoint is set to Public endpoint only.

Choose the cluster name wisely, you can leave it default but recommend to use something of your choice.

Create the cluster. Until the cluster setup is up, log in to the Ubuntu Machine.

Download the necessary tools for IBM Cloud.

Shell
 




x


 
1
curl -sL https://ibm.biz/idt-installer | bash


Login in to your IBM Cloud Account, the region, and resource group might change based on your selection.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud login -a cloud.ibm.com -r jp-tok -g default



Set the Kubernetes context to your cluster for this terminal session.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud ks cluster config --cluster "YOUR CLUSTER ID"



Verify that you can connect to your cluster.

Shell
 




xxxxxxxxxx
1


 
1
kubectl config current-context




Note: In case you forget your cluster setting, you can retrieve this information by visiting https://cloud.ibm.com/kubernetes/clusters and clicking Access under your cluster.

To verify your setting, run the following code.

Shell
 




xxxxxxxxxx
1


 
1
kubectl version --short



The following should be your output(depends on the version you are using).

Shell
 




xxxxxxxxxx
1


 
1
Client Version: v1.17.11
2
Server Version: v1.16.14+IKS



Push the SonarQube Docker Image Into IBM Cloud Container Registry

Log in to the Container Registry Service to store the SonarQube docker image


Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr login



The output should be as following, again depends on the region where you are using the container registry

Shell
 




xxxxxxxxxx
1


 
1
Logging in to 'registry.ng.bluemix.net'...
2
Logged in to 'registry.ng.bluemix.net'.
3

          
4
Logging in to 'us.icr.io'...
5
Logged in to 'us.icr.io'.
6

          
7
OK



Find your container registry namespace by running the following command

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr namespaces



The output might be as follows :

Shell
 




x
9


 
1
Listing namespaces for account 'Deepak Rai's Account' in registry 'us.icr.io'...
2

          
3
Namespace   
4
abc    
5
drname 
6
mfpbff   
7
my_names
8

          
9
OK



If you don’t have any, create one by using following command. Its always nice to maintain the image in a different namespace

Shell
 




xxxxxxxxxx
1


 
1
 ibmcloud cr namespace-add <name>



In my case, I added a new namespace sqube.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr namespace-add sqube



The output should be as follows:

Shell
 




xxxxxxxxxx
1


 
1
Adding namespace 'sqube'...
2

          
3
Successfully added namespace 'sqube'
4

          
5
OK



Identify your Container Registry by running the following command

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr info



The output will be as following:

Shell
 




xxxxxxxxxx
1


 
1
Container Registry                us.icr.io   
2
Container Registry API endpoint   https://us.icr.io/api   
3
IBM Cloud API endpoint            https://cloud.ibm.com   
4
IBM Cloud account details         Deepak Rai Account
5
IBM Cloud organization details     ()   
6

          
7
OK



Using the docker tag create a target image in the IBM Cloud container registry from the source docker registry. In this demo, I have used sonarqube:7.9.4-community edition. For more details about the version and other tags please refer :https://hub.docker.com/_/sonarqube?tab=tags

Shell
 




x


 
1
docker tag sonarqube:7.9.4-community  <REGISTRY>/<NAMESPACE>/<APPNAME>



In my case I used:

Shell
 




x


 
1
docker tag sonarqube:7.9.4-community  us.icr.io/sqube/sq:v7.9.4



Push the Docker image to your Container Registry on IBM Cloud

Shell
 




xxxxxxxxxx
1


 
1
docker push us.icr.io/sqube/sq:v7.9.4



The output should be as follows:

Shell
 




x


 
1
The push refers to repository [us.icr.io/sqube/sq]
2
d0f6eff5ea67: Pushed 
3
da6ef9551a7e: Pushed 
4
05b6b12d86c7: Pushed 
5
51c2f5ed4a22: Pushed 
6
36d4dcc9c91b: Pushed 
7
9dabcc3f61c5: Pushed 
8
4248c87e7f37: Pushed 
9
eb27fd2b2495: Pushed 
10
07cab4339852: Pushed 
11
v7.9.4: digest: sha256:xxxxxxxxxxxxxx size: 2206



Verify that the image was pushed successfully by running the following command.

Shell
 




xxxxxxxxxx
1


 
1
ibmcloud cr image-list



The output should be as follows:

Shell
 




x
10
5


 
1
Listing images...
2

          
3
Repository         Tag    Digest    Namespace Created      Size Security status   
4
us.icr.io/sqube/sq v7.9.4 1774vf    sqube     13 hours ago 287 MB   No Issues
5

          
6
OK



As you can observe, IBM Cloud container registry does one level of security scanning for you and lists all the issues. In this case there was no issues with the image. Incase you see any issues, you can login to IBM Cloud, go to registry section to understand the issues in details https://cloud.ibm.com/kubernetes/registry/main/start

Deploy Your Containerized SonarQube Application

Once you have a running Kubernetes cluster, you can deploy your containerized application on top of it. To do so, you create a Kubernetes Deployment configuration. The Deployment instructs Kubernetes on how to create and update instances of your application. Once you create a Deployment, the Kubernetes master schedules the mentioned application instances onto individual Nodes in the cluster. A Kubernetes Deployment Controller continuously monitors those instances that were created

To create a deployment, you will create a  deployment file. In this case, I have created deployment.yaml

Shell
 




xxxxxxxxxx
1


 
1
vi deployment.yaml



The YAML file consists of the following:

YAML
 




xxxxxxxxxx
1
21


 
1
apiVersion: apps/v1
2
kind: Deployment
3
metadata:
4
 name: sonarqube
5
 labels:
6
   app: sonarqube
7
spec:
8
 replicas: 1
9
 selector:
10
   matchLabels:
11
     app: sonarqube
12
 template:
13
   metadata:
14
     labels:
15
       app: sonarqube
16
   spec:
17
     containers:
18
     - name: sonarqube
19
       image: us.icr.io/sqube/sq:v7.9.4


 

Create a deployment by using the following command

Shell
 




xxxxxxxxxx
1


 
1
kubectl create -f deployment.yaml


 The output will be as follows:

Shell
 




xxxxxxxxxx
1


 
1
deployment.apps/sonarqube created



By default, the pod is only accessible by its internal IP within the cluster. Create a Kubernetes Service object that external clients can use to access an application running in a cluster. In this case, I have exposed this as a service with type LoadBalancer

Shell
 




xxxxxxxxxx
1


 
1
kubectl expose deployment.apps/sonarqube --type=LoadBalancer --port=80 --target-port=9000  



Output will be as follows:

Shell
 




xxxxxxxxxx
1


 
1
service/sonarqube exposed



Access the SonarQube Application

To verify that your application is running successfully, you need to check the STATUS of your pod. It should be in a state of Running:

Shell
 




xxxxxxxxxx
1


 
1
kubectl get pods -l app=sonarqube



Output should be as follows:

Shell
 




x


 
1
NAME                        READY   STATUS    RESTARTS   AGE
2
sonarqube-7743554c7-chvgh   1/1     Running   0          10s



To identify the public IP, run the following command:

Shell
 




xxxxxxxxxx
1


 
1
kubectl get svc -l app=sonarqube



Output should be as follows :

Shell
 




xxxxxxxxxx
1


 
1
NAME        TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)        AGE
2
sonarqube   LoadBalancer   172.21.108.13   169.59.239.67   80:30634/TCP   12h



To access the application, you can go to your browser and type http://EXTERNAL-IP:NODEPORT

In this case http://169.59.239.67:30634/

That's all folks. 

Deletion if Needed

Incase you want to delete the entire application. Run the following command

Shell
 




xxxxxxxxxx
1


 
1
kubectl delete deployment,service -l app=sonarqube



Hope you liked this article, in the next one I would write about how this can be configured in the IBM Cloud CI/CD pipeline (Toolchains) to automate the testing for your application.

Cheers!!!

IBM Cloud Kubernetes Cloud Docker (software) shell

Opinions expressed by DZone contributors are their own.

Trending

  • How To Integrate Microsoft Team With Cypress Cloud
  • Top 10 Pillars of Zero Trust Networks
  • Using Render Log Streams to Log to Papertrail
  • Merge GraphQL Schemas Using Apollo Server and Koa

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: