Rancher / k8 / azure / Kubectl

7/16/2018

I have a mysql pod in my cluster that I want to expose to a public IP. Therefor I changed it to be a loadbalancer by doing

kubectl edit svc mysql-mysql --namespace mysql

    release: mysql
  name: mysql-mysql
  namespace: mysql
  resourceVersion: "646616"
  selfLink: /api/v1/namespaces/mysql/services/mysql-mysql
  uid: cd1cce11-890c-11e8-90f5-869c0c4ba0b5
spec:
  clusterIP: 10.0.117.54
  externalTrafficPolicy: Cluster
  ports:
  - name: mysql
    nodePort: 31479
    port: 3306
    protocol: TCP
    targetPort: 3306
  selector:
    app: mysql-mysql
  sessionAffinity: None
  type: LoadBalancer
status:
  loadBalancer:
    ingress:
    - ip: 137.117.40.121

changing ClusterIP to LoadBalancer.

However I can't seem to reach it by going to mysql -h137.117.40.121 -uroot -p*****

Anyone have any idea? Is it because i'm trying to forward it over TCP?

-- Joelgullander
azure
kubectl
kubernetes-ingress
rancher

2 Answers

7/18/2018

For your issue, you want to expose your mysql pod to a public IP. So you need to take a look at Ingress in Kubernets. It's an API object that manages external access to the services in a cluster, typically HTTP. For the Ingress, you need both ingress controller and ingress rules. For more details, you can read the document I posted.

In Azure, you can get more details from HTTPS Ingress on Azure Kubernetes Service (AKS).

-- Charles Xu
Source: StackOverflow

7/22/2018

As pointed out by @aurelius, your config seems correct it's possible that the traffic is getting blocked by your firewall rules.

Also make sure, the cloud provider option is enabled for your cluster.

kubectl get svc -o wide would show the status of the LoadBalancer and the IP address allocated.

@charles-xu-msft, using Ingress is definitely an option but there is nothing wrong in using LoadBalancer kind of Service when the cloud provider is enabled for the kubernetes cluster.

Just for reference, here is test config:

apiVersion: v1
kind: Pod
metadata:
  name: mysql-pod
  labels:
    name: mysql-pod
spec:
  containers:
  - name: mysql:5
    image: mysql
    ports:
      - containerPort: 3306
    env:
      - name: MYSQL_ROOT_PASSWORD
        value: mysqlpassword
---
apiVersion: v1
kind: Service
metadata:
  name: test-mysql-lb
spec:
  type: LoadBalancer
  ports:
  - port: 3306
    targetPort: 3306
    protocol: TCP
  selector:
    name: mysql-pod
-- leodotcloud
Source: StackOverflow