garden icon indicating copy to clipboard operation
garden copied to clipboard

Missing documentation for services[].ports[].hostPort

Open mnpenner opened this issue 5 years ago • 6 comments
trafficstars

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

mnpenner avatar May 12 '20 07:05 mnpenner

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 hostPort for a Pod unless it is absolutely necessary. When you bind a Pod to a hostPort, 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 the hostIP and protocol explicitly, Kubernetes will use 0.0.0.0 as the default hostIP and TCP as the default protocol.

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 avatar May 18 '20 03:05 eysi09

@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.

mnpenner avatar May 21 '20 03:05 mnpenner

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!

stale[bot] avatar Jul 20 '20 03:07 stale[bot]

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"}]}]}}}}'

tobiasmcnulty avatar Jun 09 '22 19:06 tobiasmcnulty

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?

thsig avatar Jun 15 '22 12:06 thsig

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!

stale[bot] avatar Sep 21 '22 03:09 stale[bot]

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!

stale[bot] avatar Jan 07 '23 22:01 stale[bot]

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!

stale[bot] avatar May 21 '23 20:05 stale[bot]

Closing this as a stale one.

vvagaytsev avatar Jul 04 '23 11:07 vvagaytsev