Answers: <p>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:</p>
  <pre><code>---
  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
  </code></pre>
  <p>Per the kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">service</a> documentation:
  <em>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 :</em></p>
  <p>If you want your service available on the node port, try updating your service and deleting the other service definition.</p>
  
Answers: CC BY-SA 4.0
Answers: 2021-02-06T22:38:03.393Z
Answers: 2021-02-06T22:38:03.393Z
Answers: zm31
Body: <p>I have installed K3S kubernetes on rasbian, and created a following mysql deployment on it:</p>
  <pre><code>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: &quot;IfNotPresent&quot;
          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 
  </code></pre>
  <p>I cannot access mysql by the above definied service:</p>
  <p>I have checked the mysql service is accessable:</p>
  <pre><code>sudo kubectl exec -it mysql-d6656577c-6rdzr bash
  root@mysql-d6656577c-6rdzr:/# echo &gt; /dev/tcp/localhost/3306
  root@mysql-d6656577c-6rdzr:/# echo $?
  0
  root@mysql-d6656577c-6rdzr:/# echo &gt; /dev/tcp/mysql-d6656577c-6rdzr/3306
  root@mysql-d6656577c-6rdzr:/# echo $?
  </code></pre>
  <p>0</p>
  <p>But the service is not working:</p>
  <pre><code>root@mysql-d6656577c-6rdzr:/# echo &gt; /dev/tcp/mysql/3306
  bash: mysql: Name or service not known
  bash: /dev/tcp/mysql/3306: Invalid argument
  root@mysql-d6656577c-6rdzr:/# 
  </code></pre>
  <p>Service description:</p>
  <pre><code>sudo kubectl describe svc mysql
  Name:              mysql
  Namespace:         default
  Labels:            app=mysql
  Annotations:       kubectl.kubernetes.io/last-applied-configuration:
                       {&quot;apiVersion&quot;:&quot;v1&quot;,&quot;kind&quot;:&quot;Service&quot;,&quot;metadata&quot;:{&quot;annotations&quot;:{},&quot;labels&quot;:{&quot;app&quot;:&quot;mysql&quot;},&quot;name&quot;:&quot;mysql&quot;,&quot;namespace&quot;:&quot;default&quot;},&quot;spec&quot;:{&quot;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:            &lt;none&gt;
  </code></pre>
  <p>Core DNS logs:</p>
  <pre><code>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-&gt;8.8.8.8:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:47752-&gt;8.8.4.4:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:57505-&gt;8.8.8.8:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:51583-&gt;8.8.4.4:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:39172-&gt;8.8.8.8:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:39568-&gt;8.8.8.8:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:39343-&gt;8.8.4.4:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:40929-&gt;8.8.8.8:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:43962-&gt;8.8.8.8:53: i/o timeout
  [ERROR] plugin/errors: 2 1587632103.896807637. HINFO: read udp 10.42.0.160:47330-&gt;8.8.8.8:53: i/o timeout
  </code></pre>
  <p>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)</p>
  <pre><code>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
  </code></pre>
  <p>What can be the problem? Why I cannot access mysql?</p>
  
Tags: <kubernetes><deployment><networking>
Title: Why I cannot access k3s service from pod in rasbian?
UserDisplayName: Dániel Kis
ThreadText: # Why I cannot access k3s service from pod in rasbian?
  
  (Asked by: username_0 on 2020-05-29)
  
  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?
  
  **Tags:** kubernetes, deployment, networking
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-02-06. Score: 2 | Accepted answer
  
  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](https://kubernetes.io/docs/concepts/services-networking/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.
  
  
  ---
  
  