<p>I have a mysql service with pv, and a depoyment of a custom karaf image image.</p>
<p>I have hooks in my karaf, and when I install the kar liquibase should fill the databases, but I realise that the databases renain empty, so karaf cant access mysql.</p>
<p>I want to access in my machine, localhost.</p>
<p>Here are my .yaml configurations:</p>
<p>mysql pv:</p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 20Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: &quot;/mnt/data&quot;
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20Gi
</code></pre>
<p>mysql-deploy:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:5.7
        name: mysql
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: mysql-root-password
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: mysql-user
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: db-secret
              key: mysql-password
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mysql-persistent-storage
        persistentVolumeClaim:
          claimName: mysql-pv-claim
</code></pre>
<p>the secret with mysql pass:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: db-secret
type: Opaque
data:
  mysql-password: cm9vdA==
  mysql-root-password: cm9vdA==
  mysql-user: eGNvcmVyb290
</code></pre>
<p>karaf deploy:</p>
<pre><code>apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: karaf-deployment
spec:
  selector:
    matchLabels:
      app: karaf
  replicas: 1 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: karaf
    spec:
      containers:
      - name: karaf
        image: myuser/karaf:v1
</code></pre>
<p>Note: to connect to mysql locally I had to expose doing: <code>kubectl expose deployment mysql --type=LoadBalancer --name=my-service</code></p>
<p>Not sure if that is right...</p>
<p>and I did the same for karaf, adding <code>--port=8101</code> so I could ssh to karaf and install the kar...</p>
<p>I tried some sugestions I saw on the internet, such as create a ingress controller, or this one: <a href="https://stackoverflow.com/questions/43354167/minikube-expose-mysql-running-on-localhost-as-service">Minikube expose MySQL running on localhost as service</a></p>
<p>but didnt work :(</p>
<p>thanks for your time!</p>

Tiago Machado
<p>In Your Karaf application.what is the connection source url?
For example in a Spring boot application deploy in kubernetes and that use a mysql service the connection source url will be : jdbc:mysql://mysqlservice:3306/${DB_NAME}.
Where &quot;mysqlservice&quot; will be the name of the service mysql define in kubernetes</p>
