I am new to microk8s (coming from the Docker world) and enabled the traefik ingress controller for microk8s. Using this controller I was able to expose my services via http and https to the rest of my network successfully. Now I want to expose a non-http service (redis in this case) on port 6379 and I can’t seem to find out how to do this.
For example, in a docker-compose.yaml I used the following syntax to expose port 22 of my Gitlab:
- "traefik.tcp.routers.gitlab_ssh.rule=HostSNI(`*`)"
- "traefik.tcp.routers.gitlab_ssh.entrypoints=ssh"
- "traefik.tcp.routers.gitlab_ssh.service=service_gitlab_ssh"
- "traefik.tcp.services.service_gitlab_ssh.loadbalancer.server.port=22"
so I would expect something similar doing this with traefik in microk8s.
For standard http ignress i used this yaml (here for cyberchef):
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
generation: 5
name: cyberchef-ingress
namespace: default
spec:
ingressClassName: public
rules:
- host: cyberchef.microk8s.home.somewhere
http:
paths:
- backend:
service:
name: cyberchef-svc
port:
number: 80
path: /
pathType: Prefix
tls:
- hosts:
- cyberchef.microk8s.home.somewhere
secretName: wildcard-tls
status:
loadBalancer:
ingress:
- ip: 127.0.0.1
which works perfectly.
But of course I cannot just replace port 80 with 6379 when doing this for redis as redis is no http protocol.
The traefik documentation at Routing Configuration for Traefik CRD - Traefik talks about the CRD traefik.containo.us/v1alpha1 but I don’t seem to have this in my cluster.
How do I in general expose a service on port X to the outside world with microk8s? Please bear in mind I am a beginner here!
–
kubectl -o yaml get svc micro-redis-master
apiVersion: v1
kind: Service
metadata:
annotations:
meta.helm.sh/release-name: micro-redis
meta.helm.sh/release-namespace: default
creationTimestamp: "2022-06-09T13:05:10Z"
labels:
app.kubernetes.io/component: master
app.kubernetes.io/instance: micro-redis
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: redis
helm.sh/chart: redis-16.11.3
name: micro-redis-master
namespace: default
resourceVersion: "31115746"
selfLink: /api/v1/namespaces/default/services/micro-redis-master
uid: 8361413b-3e03-4c97-a854-20215042cba1
spec:
clusterIP: 10.152.183.178
clusterIPs:
- 10.152.183.178
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: tcp-redis
port: 6379
protocol: TCP
targetPort: redis
selector:
app.kubernetes.io/component: master
app.kubernetes.io/instance: micro-redis
app.kubernetes.io/name: redis
sessionAffinity: None
type: ClusterIP
status:
loadBalancer: {}
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 210d
whoami ClusterIP 10.152.183.147 <none> 80/TCP 209d
cyberchef-svc ClusterIP 10.152.183.145 <none> 80/TCP 209d
kuard ClusterIP 10.152.183.21 <none> 8080/TCP 201d
mysql-1638205545-headless ClusterIP None <none> 3306/TCP 191d
mysql-1638205545 ClusterIP 10.152.183.29 <none> 3306/TCP 191d
grafana ClusterIP 10.152.183.121 <none> 3000/TCP 133d
micro-redis-headless ClusterIP None <none> 6379/TCP 52m
micro-redis-replicas ClusterIP 10.152.183.216 <none> 6379/TCP 52m
micro-redis-master ClusterIP 10.152.183.178 <none> 6379/TCP 52m
kubectl get -o yaml endpoints redis
apiVersion: v1
kind: Endpoints
metadata:
annotations:
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"v1","kind":"Endpoints","metadata":{"annotations":{},"name":"redis","namespace":"default"},"subsets":[{"addresses":[{"ip":"192.168.0.93"}],"ports":[{"name":"redis","port":6379}]}]}
creationTimestamp: "2022-06-09T13:14:14Z"
name: redis
namespace: default
resourceVersion: "31116961"
selfLink: /api/v1/namespaces/default/endpoints/redis
uid: f366b549-3eea-4489-babd-c715ac8124cd
subsets:
- addresses:
- ip: 192.168.0.93
ports:
- name: redis
port: 6379
protocol: TCP