connecting to a pod from WAN using kubernetes with GCP

1/23/2018

I used Google Cloud Platform to create a Kubernetes 1.8.6 cluster.

I enabled the dashboard and I can login to it properly.

I created a deployment yaml file for mariadb installating

apiVersion: apps/v1beta2 # for versions before 1.8.0 use apps/v1beta1
kind: Deployment
metadata:
  name: mariadb-deployment
  labels:
    app: mariadb
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mariadb
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      containers:
      - name: mariadb
        image: mariadb:10.3.4
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: "<PASSWORD>"
        - name: MYSQL_USER
          value: "<USER>"
        - name: MYSQL_PASSWORD
          value: "<PASSWORD>"
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: mariadb-storage
        ports:
        - containerPort: 3306
      volumes:
      - name: mariadb-storage
        gcePersistentDisk:
            fsType: ext4
            pdName: mariadb-disk

I applied it on kubernetes. now I need to know how to open the mariadb port to my specific WAN ip so i'll be able to connect to it on port 3306.

I can see the endpoint ip of my kubernetes cluster, just no idea how to open permission to be able to connect to it from my desktop's static ip.

thanks!

-- ufk
gcp
kubernetes

1 Answer

1/24/2018

I found how to do that using the following: https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

since I already have mariadb installed on my local machine so I forwarded port 3306 on remote to be 3307 local using the following:

kubectl port-forward mariadb-deployment-<ID> 3307:3306

and that's it! i'm able to connect.

-- ufk
Source: StackOverflow