0

I have installed a Kubernetes cluster on VirtualBox (centos7) using a tutorial from here.

Here is my setup:

  • kube-master - 10.1.10.152 (etcd, kube-apiserver, kube-controller-manager, kube-scheduler)
  • kube-minion1 - 10.1.10.153 (kube-proxy, kubelet, docker, flanneld)

When i finished the setup everything looked good:

$ kubectl get nodes
NAME           LABELS                                STATUS
kube-minion1   kubernetes.io/hostname=kube-minion1   Ready

I tried to add mysql pod and service using the following config:

$ cat mysql.yaml
apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    name: mysql
spec:
      containers:
    - resources:
        limits :
          cpu: 1
      image: mysql
      name: mysql
      env:
        - name: MYSQL_ROOT_PASSWORD
          value: qwe123
      ports:
        - containerPort: 3306
          name: mysql

$ cat mysql-service.yaml 
apiVersion: v1
kind: Service
metadata:
  labels:
    name: mysql
  name: mysql
spec:
  publicIPs:
    - 10.1.10.153
  ports:
    # the port that this service should serve on
    - port: 3306
  # label keys and values that must match in order to receive traffic for this service
  selector:
    name: mysql

Notice that i do provide the publicIPs = 10.1.10.153. Once both mysql.yaml and mysql-service.yaml were injected, here is what i get:

$ kubectl get pods
NAME           READY     STATUS    RESTARTS   AGE
mysql          1/1       Running   0          31s

$ kubectl get services
NAME         LABELS                                    SELECTOR     IP(S)            PORT(S)
kubernetes   component=apiserver,provider=kubernetes   <none>       10.254.0.1       443/TCP
mysql        name=mysql                                name=mysql   10.254.215.138   3306/TCP


$ kubectl describe service mysql
Name:           mysql
Namespace:      default
Labels:         name=mysql
Selector:       name=mysql
Type:           ClusterIP
IP:             10.254.215.138
Port:           <unnamed>   3306/TCP
Endpoints:      172.17.17.5:3306
Session Affinity:   None
No events.

So the problem i am having is that mysql is not accessible using 10.1.10.153. The only way to communicate with mysql that i was able to do is accessing from the minion host using 10.254.215.138

Why am i unable to access it using 10.1.10.153? Is there a way to make it work?

Thank you -D

Dmitriy
  • 1
  • 2

1 Answers1

0

In your case simplest way will be specify service type "NodePort". In that case kubernetes will open port for the service on each node so it will be accessible via 10.1.10.153:3306. What about your case - if service type is ClusterIP then service is accessible only from inside the cluster (from the pods) independently from it's publicIp if specified.

Vyacheslav Enis
  • 1,676
  • 12
  • 17
  • I added the spec.type: "NodePort" and nodePort: 30306 and now the kubectl describe shows that NodePort is in fact 30306. But when i try to access it from the minion host using `telnet localhost 30306` i still get nothing. Do you know what could be the problem? – Dmitriy Dec 09 '15 at 23:26
  • 2
    Actually i had a problem with network config - flannel. Once that was fixed - node port is accessible. Thank you @Vyacheslav – Dmitriy Dec 10 '15 at 00:11