garden
garden copied to clipboard
Missing documentation for services[].ports[].hostPort
Bug
Current Behavior
services[].ports[].hostPort is undocumented.
Expected behavior
Document all the things.
Reproducible example
Click the link.
Workaround
Dive into the source code to figure out how it works?
Suggested solution(s)
Add some documentation.
Additional context
I'm trying to figure out how to expose MariaDB to my host machine for testing. Not sure if I'm supposed to use hostPort or ingress or what. Ingress seems funny because it's not HTTP.
Your environment
Chrome 81
Hi @mnpenner!
You're right, this field is missing documentation. We're actually deprecating it because it's generally advised against using it, from the K8s docs:
Don’t specify a
hostPortfor a Pod unless it is absolutely necessary. When you bind a Pod to ahostPort, it limits the number of places the Pod can be scheduled, because each<hostIP, hostPort, protocol>combination must be unique. If you don’t specify thehostIPandprotocolexplicitly, Kubernetes will use0.0.0.0as the defaulthostIPandTCPas the defaultprotocol.
If you only need access to the port for debugging purposes, you can use the apiserver proxy or kubectl port-forward.
If you explicitly need to expose a Pod’s port on the node, consider using a NodePort Service before resorting to
hostPort.
So in your case, you should be able to reach the DB by creating an ingress.
@eysi09 You sure? This says:
Ingress does not support TCP or UDP services
But it does propose an alternative solution. Maybe I'll try that. Port-forwarding would probably also work for dev.
This issue has been automatically marked as stale because it hasn't had any activity in 60 days. It will be closed in 14 days if no further activity occurs (e.g. changing labels, comments, commits, etc.). Please feel free to tag a maintainer and ask them to remove the label if you think it doesn't apply. Thank you for submitting this issue and helping make Garden a better product!
I couldn't find a way to get this working either. Here's what we ended up doing instead:
# hostPort does not appear to work in Garden (and is deprecated), so we need add it ourselves.
# https://docs.garden.io/reference/module-types/container#services-.ports-.hostport
kind: Command
name: expose-mysql
description:
short: Patch the garden Deployment to expose the MySQL port.
exec:
command:
- kubectl
- -n
- db-default
- patch
- deployment
- mysql
- --patch
- '{"spec": {"template": {"spec": {"containers": [{"name": "mysql", "ports": [{"containerPort": 3306, "hostPort": 3306, "name": "mysql", "protocol": "TCP"}]}]}}}}'
While this field is still marked for deprecation, I thought I'd suggest having a look at configuring port-forwards for the service. See the reference docs here.
Note that these port-forwards are only started when running a watch-mode command (e.g. garden deploy --dev or garden dev), but this should be good approach during development.
Did you run into problems with this method?
This issue has been automatically marked as stale because it hasn't had any activity in 90 days. It will be closed in 14 days if no further activity occurs (e.g. changing labels, comments, commits, etc.). Please feel free to tag a maintainer and ask them to remove the label if you think it doesn't apply. Thank you for submitting this issue and helping make Garden a better product!
This issue has been automatically marked as stale because it hasn't had any activity in 90 days. It will be closed in 14 days if no further activity occurs (e.g. changing labels, comments, commits, etc.). Please feel free to tag a maintainer and ask them to remove the label if you think it doesn't apply. Thank you for submitting this issue and helping make Garden a better product!
This issue has been automatically marked as stale because it hasn't had any activity in 90 days. It will be closed in 14 days if no further activity occurs (e.g. changing labels, comments, commits, etc.). Please feel free to tag a maintainer and ask them to remove the label if you think it doesn't apply. Thank you for submitting this issue and helping make Garden a better product!
Closing this as a stale one.