In Helm-based installation, while deploying Artifactory with PostgreSQL database, In some scenarios, Artifactory was not able to connect to the Database and it is hard to check the connectivity with the Database from the POD as Artifactory images have minimal libraries installed as a lightweight container. To check whether the Database is reachable from Artifactory Pod we can add a PostgreSQL as a sidecar container with the Artifactory Pod and check the connection using psql client.
Below are the steps to add a sidecar container with Artifactory Pod.
1. Add the below sidecar containers definition for the Artifactory with PostgreSQL client in values.yaml file.
artifactory: node: replicaCount: 1 masterKeySecretName: my-masterkey-secret joinKeySecretName: my-joinkey-secret license: secret: artifactory-cluster-license dataKey: art.lic customSidecarContainers: | - name: "sidecar-for-postgresql-clinet" image: postgres imagePullPolicy: IfNotPresent command: - 'sleep' - '604800' postgresql: enabled: false database: type: postgresql driver: org.postgresql.Driver url: "jdbc:postgresql://<database-hostname>:5432/<artifactory-db-name>" user: <database-username> password: <database-password> databaseUpgradeReady: true unifiedUpgradeAllowed: true nginx: enabled: trueNote: Here we are adding the ‘sleep 604800’ command so that the container will be running and we can log in inside the sidecar container to execute the commands needed.
2. Deploy/Upgrade Artifactory using helm upgrade command-
helm upgrade --install artifactory -f values.yaml -n artifactory jfrog/artifactory
3. When Artifactory deployed successfully, describe the Artifactory pod to check the status of the PostgreSQL sidecar container. In our case, we named the sidecar container as “sidecar-list-etc”.
sidecar-list-etc: Container ID: containerd://fde9a1ff6b82243334ac2ddd8484474e99f7023ff03d4a1282b5a9f12a96afeb Image: postgres Image ID: docker.io/library/postgres@sha256:a80d0c1b119cf3d6bab27f72782f16e47ab8534ced937fa813ec2ab26e1fd81e Port: <none> Host Port: <none> Command: sleep 604800 State: Running Started: Mon, 13 Nov 2023 16:16:33 +0530 Ready: True Restart Count: 0 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-zrrl5 (ro)From the above output, we can see that the sidecar container is running.
Also, to check how many containers the Artifactory pod have, we can use the below command-
kubectl get pods artifactory-0 -o jsonpath='{.spec.containers[*].name}' -n artifactory
This will give the list of containers in artifactory-0 pod
router frontend metadata event jfconnect integration observability artifactory sidecar-list-etc%
4. Login to the PostgreSQL sidecar container “sidecar-list-etc”
kubectl exec -it artifactory-0 -n artifactory -c sidecar-for-postgresql-clinet bash
5. To connect the PostgreSQL database with a psql client or sidecar container use the below command. If you are using the default PostgreSQL that comes with the Artifactory Helm chart the hostname will be the svc name of the PostgreSQL statefulset.
psql -h <postgresql-hostname-or-IP> -p <port> -U <database-username> <database-name>
Note: Once the debugging is completed it is always better to remove the sidecar containers so no unwanted resource will be held or executing unwanted tasks in the Artifactory pod.