1
votes

I am a newbie in kubernetes and i know i am missing something small but cannot see what. I am creating a pod with file: kubectl create -f mysql.yaml

apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  containers:
    - resources:
        limits :
          cpu: 2
      image: mysql
      name: mysql
      env:
        - name: MYSQL_ROOT_PASSWORD
          # change this
          value: TestingDB1
      ports:
        - containerPort: 3306
          name: mysql

and a service with: kubectl create -f mysql_service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    name: mysql
  name: mysql
spec:
  externalIPs:
    - 10.19.13.127
  ports:
    - port: 3306
  selector:
    name: mysql

Output of "kubectl version"

Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"d33fd89e399396658aed4e48dfe7d5d8d50ac6e8", GitTreeState:"clean", BuildDate:"2017-05-26T17:08:24Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"d33fd89e399396658aed4e48dfe7d5d8d50ac6e8", GitTreeState:"clean", BuildDate:"2017-05-26T17:08:24Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}

Output of "kubectl cluster-info"

Kubernetes master is running at http://localhost:8080

Output of "kubectl get pods"

NAME                    READY     STATUS    RESTARTS   AGE
mysql                   1/1       Running   0          20m

Output of "kubectl get svc"

NAME         CLUSTER-IP       EXTERNAL-IP    PORT(S)    AGE
kubernetes   10.254.0.1       <none>         443/TCP    18h
mysql        10.254.129.206   10.19.13.127   3306/TCP   1h

Output of "kubectl get no"

NAME           STATUS    AGE
10.19.13.127   Ready     19h

Output of "docker ps"

CONTAINER ID        IMAGE                                      COMMAND                  CREATED             STATUS              PORTS               NAMES
74ea1fb2b383        mysql                                      "docker-entrypoint.sh"   3 minutes ago       Up 3 minutes                            k8s_mysql.ae7893ad_mysql_default_e58d1c09-4a8e-11e7-9baf-fa163ee3f5d9_793d8d7c

I can see the pod is being created normally. Even when i connect to the container I am able to log in to mysql with credentials.

My question is: How can i access/expose port running on my kubernetes node from my network ? For example I want to do a telnet from my PC to the kubernetes node where the mysql pod is running.

Thank you !

2
With that config you should be able to access to your pod via 10.19.13.127:3306. Have you tried "telnet 10.19.13.127 3306"? What happens? Have you checked firewall rules?aespejel

2 Answers

0
votes

Below command verifies that the Redis server is running in the pod and listening on which port (generally it run on 6379 port) :

kubectl get pods redis-master --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}'

Output : 6739

0
votes

Following command gives you port a pod listening on, so you can create route or port forwarding to access the service

kubectl get pod <pod_name> -o "go-template={{(index (index .spec.containers 0).ports 0).containerPort}}