iTop is a popular open-source Configuration Management Database (CMDB) tool used for IT asset management and IT service management. In this article, we will guide you through the process of installing iTop CMDB on a Kubernetes cluster using various YAML files and configuring the database. This installation will help you centralize and manage your IT assets effectively.
Prerequisites:
Before you begin the installation process, ensure that you have the following prerequisites in place:
A Kubernetes cluster up and running.
kubectl command-line tool installed and configured to access your cluster.
The necessary YAML files for iTop, including deployment_itops.yaml, svc_itops.yaml, mysql-secret.yaml, mysql-deployment.yaml, and mysql-svc.yaml.
Installation Steps:
Create a Kubernetes Namespace:
To isolate the iTop installation, create a dedicated namespace using the following command:kubectl create namespace itops
Set the Namespace Context:
Change the current context to the 'itops' namespace to ensure that subsequent commands apply to the correct namespace:kubectl config set-context --current --namespace=itops
Deploy iTop Application:
Deploy the iTop application using the 'deployment_itops.yaml' file:kubectl apply -f deployment_itops.yaml
apiVersion: apps/v1 kind: Deployment metadata: name: itops-cmdb-deployment spec: replicas: 1 selector: matchLabels: app: itops-cmdb template: metadata: labels: app: itops-cmdb spec: containers: - name: itops-cmdb image: vbkunin/itop:2.7.1 ports: - containerPort: 80
Create iTop Service:
Create the iTop service using the 'svc_itops.yaml' file:kubectl apply -f svc_itops.yaml
apiVersion: v1
kind: Service
metadata:
name: itops-cmdb-service
spec:
selector:
app: itops-cmdb
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Create MySQL Secrets:
Deploy the MySQL secrets using the 'mysql-secret.yaml' file. These secrets are necessary for the connection between iTop and the MySQL database:kubectl apply -f mysql-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: mysql-secret
type: Opaque
data:
MYSQL_ROOT_PASSWORD: UHJlbWFAMTk2NQ==
MYSQL_USER: aXRvcHM=
MYSQL_PASSWORD: UHJlbWFAMTk2NQ==
stringData:
configMapRef: mysql-config
To get the above secret encoded values:
echo -n '<<MYSQL_ROOT_PASSWORD>>' | base64
UHJlbWFAMTk2NQ==
echo -n '<<MYSQL_USER>>' | base64
aXRvcHM=
Deploy MySQL Database:
Deploy the MySQL database using the 'mysql-deployment.yaml' file:kubectl apply -f mysql-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
spec:
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
envFrom:
- secretRef:
name: mysql-secret
ports:
- containerPort: 3306
resources:
requests:
memory: "512Mi"
cpu: "250m"
limits:
memory: "1Gi"
cpu: "500m"
Create MySQL Service:
Create the MySQL service using the 'mysql-svc.yaml' file:kubectl apply -f mysql-svc.yaml
apiVersion: v1 kind: Service metadata: name: mysql-service spec: type: LoadBalancer selector: app: mysql ports: - protocol: TCP port: 3306 targetPort: 3306
Check External IP:
To access the iTop application, you'll need to find the external IP of the iTop service. Use the following command to retrieve it:kubectl get svc -n itops
Note down the external IP provided for the iTop service.
kubectl exec -it mysql-deployment-698cdf4c88-f727r -- /bin/sh
mysql -u root -p
CREATE DATABASE itops;
SHOW DATABASES;
GRANT ALL PRIVILEGES ON itops.* TO 'itops'@'%';
Access iTop from the UI:
Open a web browser and enter the external IP obtained in the previous step. You should now be able to access the iTop CMDB tool from the web interface.
Script to be run inside the pod to set Parameters to get rid of the initial error:
Fatal error: Uncaught ConfigException: Syntax error in configuration file: file = /var/www/html/conf/production/config-itop.php, error = <tt><br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_DATABASE" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>5</b><br /> <br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_USER" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>6</b><br /> <br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_PASSWORD" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>7</b><br /></tt> in /var/www/html/core/config.class.inc.php:1996 Stack trace: #0 /var/www/html/core/config.class.inc.php(1911): Config->Load() #1 /var/www/html/core/metamodel.class.php(6313): Config->__construct() #2 /var/www/html/application/startup.inc.php(102): MetaModel::Startup() #3 /var/www/html/pages/UI.php(303): require_once('/var/www/html/a...') #4 {main} Next ConfigException: Syntax error in configuration file: file = /var/www/html/conf/production/config-itop.php, error = <tt><br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_DATABASE" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>5</b><br /> <br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_USER" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>6</b><br /> <br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_PASSWORD" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>7</b><br /></tt> in /var/www/html/core/config.class.inc.php:1996 Stack trace: #0 /var/www/html/core/config.class.inc.php(1911): Config->Load() #1 /var/www/html/application/utils.inc.php(962): Config->__construct() #2 /var/www/html/application/utils.inc.php(3110): utils::GetConfig() #3 /var/www/html/application/utils.inc.php(3076): utils::GetDeveloperModeParam() #4 /var/www/html/application/utils.inc.php(2866): utils::IsDevelopmentEnvironment() #5 /var/www/html/sources/Service/Events/EventService.php(44): utils::GetClassesForInterface() #6 /var/www/html/core/metamodel.class.php(6331): Combodo\iTop\Service\Events\EventService::InitService() #7 /var/www/html/application/startup.inc.php(102): MetaModel::Startup() #8 /var/www/html/pages/UI.php(303): require_once('/var/www/html/a...') #9 {main} thrown in /var/www/html/core/config.class.inc.php on line 1996
Fatal error: Uncaught ConfigException: Syntax error in configuration file: file = /var/www/html/conf/production/config-itop.php, error = <tt><br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_DATABASE" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>5</b><br /> <br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_USER" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>6</b><br /> <br /> <b>Warning</b>: Undefined array key "DB_ENV_MYSQL_PASSWORD" in <b>/var/www/html/core/config.class.inc.php(1976) : eval()'d code</b> on line <b>7</b><br /></tt> in /var/www/html/core/config.class.inc.php:1996 Stack trace: #0 /var/www/html/core/config.class.inc.php(1911): Config->Load() #1 /var/www/html/application/utils.inc.php(962): Config->__construct() #2 /var/www/html/core/log.class.inc.php(948): utils::GetConfig() #3 /var/www/html/core/log.class.inc.php(839): LogAPI::GetConfig() #4 /var/www/html/core/log.class.inc.php(827): LogAPI::GetLogConfig() #5 /var/www/html/core/log.class.inc.php(783): LogAPI::GetMinLogLevel() #6 /var/www/html/core/log.class.inc.php(761): LogAPI::IsLogLevelEnabled() #7 /var/www/html/core/log.class.inc.php(746): LogAPI::WriteLog() #8 /var/www/html/core/log.class.inc.php(703): LogAPI::Log() #9 /var/www/html/application/startup.inc.php(56): LogAPI::Error() #10 [internal function]: {closure}() #11 {main} thrown in /var/www/html/core/config.class.inc.php on line 1996
kubectl exec -it itops-cmdb-deployment-7f7f454c5d-8v5cn -- /bin/sh
# Define the new values
new_db_host="4.157.56.11"
new_db_name="itops"
new_db_user="itops"
new_db_pwd="Prema@1965"
# Replace values in the file
sed -i "s/\$_ENV\['DB_HOSTNAME'\]/'$new_db_host'/" /var/www/html/conf/production/config-itop.php
sed -i "s/\$_ENV\['DB_ENV_MYSQL_DATABASE'\]/'$new_db_name'/" /var/www/html/conf/production/config-itop.php
sed -i "s/\$_ENV\['DB_ENV_MYSQL_USER'\]/'$new_db_user'/" /var/www/html/conf/production/config-itop.php
sed -i "s/\$_ENV\['DB_ENV_MYSQL_PASSWORD'\]/'$new_db_pwd'/" /var/www/html/conf/production/config-itop.php