<p>i am trying to spring init container of liquibase which has some scripts which take time
i want to execute these script before the spring ms containers come alive</p>
<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: db-conf           # name of ConfigMap, referenced in other files
  namespace: default
data:
  host: &quot;mysql&quot;            # host address of mysql server, we are using DNS of Service
  name: &quot;espark-mysql&quot;     # name of the database for application
  port: &quot;3306&quot;
</code></pre>
<pre><code># Define 'Secret' to store 'root' user Credentials
apiVersion: v1
kind: Secret
metadata:
  name: db-root-credentials # Name of the Secret
  namespace: default
data:   #to create secret $ echo -n 'valuexxxx' | base64
  username: cm9vdA== # base64 encoded 'root' username
  password: cm9vdA== # base64 encoded 'root' password  
</code></pre>
<pre><code># Define a 'Service' To Expose mysql to Other Services
apiVersion: v1
kind: Service
metadata:
  name: mysql  # DNS name
  labels:
    app: mysql
    tier: database
spec:
  ports:
    - port: 3306
      targetPort: 3306
  selector:       # mysql Pod Should contain same labels
    app: mysql
    tier: database
  clusterIP: None  # We Use DNS, Thus ClusterIP is not relevant
---
# Define a 'Persistent Volume Claim'(PVC) for Mysql Storage, dynamically provisioned by cluster
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim # name of PVC essential for identifying the storage data
  labels:
    app: mysql
    tier: database
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
# Configure 'Deployment' of mysql server
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
  labels:
    app: mysql
    tier: database
spec:
  selector: # mysql Pod Should contain same labels
    matchLabels:
      app: mysql
      tier: database
  strategy:
    type: Recreate
  template:
    metadata:
      labels: # Must match 'Service' and 'Deployment' selectors
        app: mysql
        tier: database
    spec:
      containers:
        - image: mysql:5.7 # image from docker-hub
          args:
            - &quot;--ignore-db-dir=lost+found&quot; # Workaround for https://github.com/docker-library/mysql/issues/186
          name: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD # Setting Root Password of mysql From a 'Secret'
              valueFrom:
                secretKeyRef:
                  name: db-root-credentials # Name of the 'Secret'
                  key: password   # 'key' inside the Secret which contains required 'value'
            - name: MYSQL_DATABASE # Setting Database Name from a 'ConfigMap'
              valueFrom:
                configMapKeyRef:
                  name: db-conf
                  key: name
          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:        # Mounting voulume obtained from Persistent Volume Claim
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage # Obtaining 'volume' from PVC
          persistentVolumeClaim:
            claimName: mysql-pv-claim
</code></pre>
<pre><code># Define 'Service' to expose backend application deployment
apiVersion: v1
kind: Service
metadata:
  name: springboot-mysql-service
  namespace: default
spec:
  selector: # backend application pod labels should match these
    app: springboot-mysql-service-label
    tier: backend
  ports:
    - protocol: TCP
      port: 9090
      targetPort: 9090
  type: LoadBalancer # use NodePort, if you are not running Kubernetes on cloud
---
# Configure 'Deployment' of backend application
apiVersion: apps/v1
kind: Deployment
metadata:
  name: springboot-mysql-service
  labels:
    app: springboot-mysql-service-label
    tier: backend
spec:
  replicas: 1 # Number of replicas of back-end application to be deployed
  selector:
    matchLabels: # backend application pod labels should match these
      app: springboot-mysql-service-label
      tier: backend
  template:
    metadata:
      labels: # Must match 'Service' and 'Deployment' labels
        app: springboot-mysql-service-label
        tier: backend
    spec:
      initContainers:
        - name: liquibase
          image: adarshkumarsingh83/springboot-liquibase-mysql
          imagePullPolicy: IfNotPresent
          env:
            - name: SPRING_PROFILES_ACTIVE
              value: kubernates
            - name: DATABASE_HOST
              valueFrom:
                configMapKeyRef:
                  name: db-conf
                  key: host
            - name: DATABASE_PORT
              valueFrom:
                configMapKeyRef:
                  name: db-conf
                  key: port
            - name: DATABASE_NAME
              valueFrom:
                configMapKeyRef:
                  name: db-conf
                  key: name          
            - name: DATABASE_USER
              valueFrom:
                secretKeyRef:
                  name: db-root-credentials
                  key: username
            - name: DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-root-credentials
                  key: password
      containers:
        - name: springboot-mysql-service
          image: adarshkumarsingh83/springboot-mysql-service # docker image of backend application
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9090
          env: # Setting environmental Variables
            - name: SPRING_PROFILES_ACTIVE
              value: kubernates
            - name: DATABASE_HOST # Setting Database host address from configMap
              valueFrom:
                configMapKeyRef:
                  name: db-conf # name of configMap
                  key: host
            - name: DATABASE_PORT
              valueFrom:
                configMapKeyRef:
                  name: db-conf
                  key: port  
            - name: DATABASE_NAME
              valueFrom:
                configMapKeyRef:
                  name: db-conf
                  key: name
            - name: DATABASE_USER # Setting Database username from Secret
              valueFrom:
                secretKeyRef:
                  name: db-root-credentials # Secret Name
                  key: username
            - name: DATABASE_PASSWORD # Setting Database password from Secret
              valueFrom:
                secretKeyRef:
                  name: db-root-credentials
                  key: password
</code></pre>
<p>i am trying to execute the yaml with are in this below link</p>
<p><a href="https://github.com/adarshkumarsingh83/kubernetes/tree/master/APPLICATIONS/springboot-kubernates-lisquibase-initcontainer-mysql/kuberantes" rel="nofollow noreferrer">https://github.com/adarshkumarsingh83/kubernetes/tree/master/APPLICATIONS/springboot-kubernates-lisquibase-initcontainer-mysql/kuberantes</a></p>
<p>but some how only spring containers is working and liquibase init container is not executing and db and tables are not created due to that</p>
<p>any sort of help is appreciated</p>

Adarsh Kumar
<p>with same configuration i am able to run the liquibase init container
and after that spring boot containers work fine and able to get the data which is created by liqibase init container</p>
<pre><code>$ kubectl logs -f springboot-mysql-service-7f4f8fd9df-vgnr7  -c liquibase

                        ,--.                    ,--. ,--.                  ,--. ,--.
 ,---.   ,---.  ,--.--. `--' ,--,--,   ,---.    |  | `--'  ,---.  ,--.,--. `--' |  |-.   ,--,--.  ,---.   ,---.
(  .-'  | .-. | |  .--' ,--. |      \ | .-. |   |  | ,--. | .-. | |  ||  | ,--. | .-. ' ' ,-.  | (  .-'  | .-. :
.-'  `) | '-' ' |  |    |  | |  ||  | ' '-' '   |  | |  | ' '-' | '  ''  ' |  | | `-' | \ '-'  | .-'  `) \   --.
`----'  |  |-'  `--'    `--' `--''--' .`-  /    `--' `--'  `-|  |  `----'  `--'  `---'   `--`--' `----'   `----'
        `--'                          `---'                  `--'
2022-08-29 17:01:11.977  INFO 1 --- [           main] c.e.a.SpringbootLiquibaseApplication     : Starting SpringbootLiquibaseApplication v0.0.1-SNAPSHOT using Java 11.0.16 on springboot-mysql-service-7f4f8fd9df-vgnr7 with PID 1 (/springboot-liquibase-mysql.jar started by root in /)
2022-08-29 17:01:11.980  INFO 1 --- [           main] c.e.a.SpringbootLiquibaseApplication     : The following 1 profile is active: &quot;kubernates&quot;
2022-08-29 17:01:13.120  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : hikar-pool - Starting...
2022-08-29 17:01:13.529  INFO 1 --- [           main] com.zaxxer.hikari.HikariDataSource       : hikar-pool - Start completed.
2022-08-29 17:01:14.185  INFO 1 --- [           main] liquibase.lockservice                    : Successfully acquired change log lock
2022-08-29 17:01:14.202  INFO 1 --- [           main] liquibase.command                        : Dropping Database Objects in schema: espark-mysql.espark-mysql
2022-08-29 17:01:14.236  INFO 1 --- [           main] liquibase.changelog                      : Creating database history table with name: `espark-mysql`.DATABASECHANGELOG
2022-08-29 17:01:14.550  INFO 1 --- [           main] liquibase.database                       : Successfully deleted all supported object types in schema espark-mysql.espark-mysql.
2022-08-29 17:01:14.552  INFO 1 --- [           main] liquibase.lockservice                    : Successfully released change log lock
All objects dropped from root@172.17.0.4@jdbc:mysql://mysql:3306/espark-mysql?createDatabaseIfNotExist=true&amp;useSSL=false
2022-08-29 17:01:14.583  INFO 1 --- [           main] liquibase.lockservice                    : Successfully acquired change log lock
2022-08-29 17:01:15.004  INFO 1 --- [           main] liquibase.changelog                      : Creating database history table with name: `espark-mysql`.DATABASECHANGELOG
2022-08-29 17:01:15.016  INFO 1 --- [           main] liquibase.changelog                      : Reading from `espark-mysql`.DATABASECHANGELOG
Running Changeset: db/changelog/db.changelog-master.xml::1::adarsh
2022-08-29 17:01:15.076  INFO 1 --- [           main] liquibase.changelog                      : SQL in file db/changelog/changes/sql/create_schema.sql executed
2022-08-29 17:01:15.077  INFO 1 --- [           main] liquibase.changelog                      : ChangeSet db/changelog/db.changelog-master.xml::1::adarsh ran successfully in 20ms
Running Changeset: db/changelog/db.changelog-master.xml::2::radha
2022-08-29 17:01:15.093  INFO 1 --- [           main] liquibase.changelog                      : SQL in file db/changelog/changes/sql/insert_data.sql executed
2022-08-29 17:01:15.096  INFO 1 --- [           main] liquibase.changelog                      : ChangeSet db/changelog/db.changelog-master.xml::2::radha ran successfully in 13ms
Running Changeset: db/changelog/db.changelog-master.xml::3::radha
2022-08-29 17:01:15.108  INFO 1 --- [           main] liquibase.changelog                      : SQL in file db/changelog/changes/sql/select_data.sql executed
2022-08-29 17:01:15.109  INFO 1 --- [           main] liquibase.changelog                      : ChangeSet db/changelog/db.changelog-master.xml::3::radha ran successfully in 7ms
2022-08-29 17:01:15.120  INFO 1 --- [           main] liquibase.lockservice                    : Successfully released change log lock
2022-08-29 17:01:15.321  INFO 1 --- [           main] c.e.a.SpringbootLiquibaseApplication     : Started SpringbootLiquibaseApplication in 4.2 seconds (JVM running for 4.731)
2022-08-29 17:01:15.333  INFO 1 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : hikar-pool - Shutdown initiated...
2022-08-29 17:01:15.355  INFO 1 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : hikar-pool - Shutdown completed.
2022-08-29 14:11:38.586  INFO 1 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : hikar-pool - Shutdown completed.

</code></pre>
