debugkubernetesMinor
Why I cannot access k3s service from pod in rasbian?
Viewed 0 times
cannotwhyk3sservicerasbianfrompodaccess
Problem
I have installed K3S kubernetes on rasbian, and created a following mysql deployment on it:
``
- 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
``
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
Solution
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:
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.
---
apiVersion: v1
kind: Service
metadata:
name: mysql
labels:
app: mysql
spec:
type: NodePort
selector:
app: mysql
ports:
- port: 3306
name: mysql
targetPort: 3306
nodePort: 30036Per 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.
Code Snippets
---
apiVersion: v1
kind: Service
metadata:
name: mysql
labels:
app: mysql
spec:
type: NodePort
selector:
app: mysql
ports:
- port: 3306
name: mysql
targetPort: 3306
nodePort: 30036Context
StackExchange DevOps Q#11719, answer score: 2
Revisions (0)
No revisions yet.