2

I have installed K3S kubernetes on rasbian, and created a following mysql deployment on it:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-data
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 100Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-config
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 100Mi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-log
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: local-path
  resources:
    requests:
      storage: 100Gi
---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  ports:
  - port: 3306
    name: mysql
    targetPort: 3306
  selector:
    app: mysql

---

apiVersion: v1
kind: Service
metadata:
  name: mysql-nodeport
spec:
  type: NodePort
  selector:
    app: mysql
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the `port` field.
    - port: 3306
      targetPort: 3306
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767)
      nodePort: 30036
 
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql
spec:
  selector:
    matchLabels:
      app: mysql
  replicas: 1
  template:
    metadata:
      labels:
        app: mysql
    spec:
      securityContext:
        fsGroup: 999 
      containers:
      - name: mysql
        image: hypriot/rpi-mysql:latest
        imagePullPolicy: "IfNotPresent"
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: mypassword
        ports:
        - containerPort: 3306
        volumeMounts:
        - mountPath: /var/lib/mysql
          name: mysql-data
        - mountPath: /var/log/mysql
          name: mysql-log
        - mountPath: /etc/mysql
          name: mysql-config
      volumes:
      - name: mysql-data
        persistentVolumeClaim:
          claimName: mysql-data
      - name: mysql-config
        persistentVolumeClaim:
          claimName: mysql-config
      - name: mysql-log
        persistentVolumeClaim:
          claimName: mysql-log
      nodeSelector:
        mysql: master 

I cannot access mysql by the above definied service:

I have checked the mysql service is accessable:

sudo kubectl exec -it mysql-d6656577c-6rdzr bash
root@mysql-d6656577c-6rdzr:/# echo > /dev/tcp/localhost/3306
root@mysql-d6656577c-6rdzr:/# echo $?
0
root@mysql-d6656577c-6rdzr:/# echo > /dev/tcp/mysql-d6656577c-6rdzr/3306
root@mysql-d6656577c-6rdzr:/# echo $?

0

But the service is not working:

root@mysql-d6656577c-6rdzr:/# echo > /dev/tcp/mysql/3306
bash: mysql: Name or service not known
bash: /dev/tcp/mysql/3306: Invalid argument
root@mysql-d6656577c-6rdzr:/# 

Service description:

sudo kubectl describe svc mysql
Name:              mysql
Namespace:         default
Labels:            app=mysql
Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                     {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"mysql"},"name":"mysql","namespace":"default"},"spec":{"p...
Selector:          app=mysql
Type:              ClusterIP
IP:                10.43.58.35
Port:              mysql  3306/TCP
TargetPort:        3306/TCP
Endpoints:         10.42.0.161:3306
Session Affinity:  None
Events:            <none>

Core DNS logs:

sudo kubectl logs -f coredns-d798c9dd-npbj4 --namespace=kube-system
.:53
[INFO] plugin/reload: Running configuration MD5 = 4665410bf21c8b272fcfd562c482cb82
   ______                ____  _   _______
  / ____/___  ________  / __ \/ | / / ___/  ~ CoreDNS-1.6.3
 / /   / __ \/ ___/ _ \/ / / /  |/ /\__ \   ~ linux/arm, go1.12.9, 37b9550
/ /___/ /_/ / /  /  __/ /_/ / /|  /___/ / 
\____/\____/_/   \___/_____/_/ |_//____/  
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:34250->8.8.8.8:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:47752->8.8.4.4:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:57505->8.8.8.8:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:51583->8.8.4.4:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:39172->8.8.8.8:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:39568->8.8.8.8:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:39343->8.8.4.4:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:40929->8.8.8.8:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:43962->8.8.8.8:53: i/o timeout
[ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:47330->8.8.8.8:53: i/o timeout

I cannot understand this, because 8.8.8.8 is accessable from host raspberry pi and 8.8.8.8 not contains local dns names (for instance: mysql)

ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=55 time=10.10 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=55 time=11.3 ms

What can be the problem? Why I cannot access mysql?

1

It looks like you are configuring two services, mysql and mysql-nodeport to use the same port. Without information to indicate otherwise im assuming this is a 1 node setup with rasbian. I personally dont have raspbian installed to test, but try something like this:

---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  labels:
    app: mysql
spec:
  type: NodePort
  selector:
    app: mysql
  ports:
  - port: 3306
    name: mysql
    targetPort: 3306
    nodePort: 30036

Per the kubernetes service documentation: NodePort: Exposes the Service on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the NodePort Service, from outside the cluster, by requesting :

If you want your service available on the node port, try updating your service and deleting the other service definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.