*Cross-posted from k3d GitHub Discussion: https://github.com/rancher/k3d/discussions/690
I am attempting to expose two services over two ports. As an alternative, I'd also love to know how to expose them over the same port and use different routes. I've attempted a few articles and a lot of configurations. Let me know where I'm going wrong with the networking of k3d + k3s / kubernetes + traefik (+ klipper?)...
I posted an example: https://github.com/ericis/k3d-networking
The goal:
- Reach "app-1" on host over port 8080
- Reach "app-2" on host over port 8091
Steps
*See: files in repo
Configure
k3d
cluster and expose app ports to load balancerports: # map localhost to loadbalancer - port: 8080:80 nodeFilters: - loadbalancer # map localhost to loadbalancer - port: 8091:80 nodeFilters: - loadbalancer
Deploy apps with "deployment.yaml" in Kubernetes and expose container ports
ports: - containerPort: 80
Expose services within kubernetes. Here, I've tried two methods.
Using CLI
$ kubectl create service clusterip app-1 --tcp=8080:80 $ kubectl create service clusterip app-2 --tcp=8091:80
Using "service.yaml"
spec: ports: - protocol: TCP # expose internally port: 8080 # map to app targetPort: 80 selector: run: app-1
Expose the services outside of kubernetes using "ingress.yaml"
backend: service: name: app-1 port: # expose from kubernetes number: 8080