diff --git a/docs/connection-from-host.md b/docs/connection-from-host.md new file mode 100644 index 000000000..84eec198f --- /dev/null +++ b/docs/connection-from-host.md @@ -0,0 +1,29 @@ +# Connection from host + +### Using NodePort + +To connect to a node from your host machine, you can use the NodePort service type. This exposes the node's desired ports on the host machine, allowing you to connect to them directly. + +For example to connect to a Bitcoin Core node using the RPC port, add this to the node's configuration in the network graph definition: + +```yaml +nodes: + - name: tank-0001 + service: + type: NodePort + rpcNodePort: 30443 +``` + +Then you can connect to the node with `localhost:30443`. Or in non-local cluster `:30443`. + +All the different port options can be seen in values.yaml files. The exposed port values must be in the range 30000-32767. If left empty, a random port in that range will be assigned by Kubernetes. + +To check which ports are open on the host machine, use `kubectl get svc -n ` and look for the `PORT(S)` column. + +### Using port-forward + +Alternatively, you can use `kubectl port-forward` command. For example to expose the regtest RPC port of a Bitcoin Core node, run the below. The first port is the local port on your machine, and the second port is the port inside the cluster. You can choose any available local port. + +```shell +kubectl port-forward pod/tank-0001 18443:18443 +``` \ No newline at end of file diff --git a/resources/charts/bitcoincore/charts/cln/templates/service.yaml b/resources/charts/bitcoincore/charts/cln/templates/service.yaml index 565f50182..2e6a911c0 100644 --- a/resources/charts/bitcoincore/charts/cln/templates/service.yaml +++ b/resources/charts/bitcoincore/charts/cln/templates/service.yaml @@ -12,13 +12,22 @@ spec: targetPort: p2p protocol: TCP name: p2p + {{- if and (eq .Values.service.type "NodePort") (.Values.service.p2pNodePort) }} + nodePort: {{ .Values.service.p2pNodePort }} + {{- end }} - port: {{ .Values.RPCPort }} targetPort: rpc protocol: TCP name: rpc + {{- if and (eq .Values.service.type "NodePort") (.Values.service.rpcNodePort) }} + nodePort: {{ .Values.service.rpcNodePort }} + {{- end }} - port: {{ .Values.RestPort }} targetPort: rest protocol: TCP name: rest + {{- if and (eq .Values.service.type "NodePort") (.Values.service.restNodePort) }} + nodePort: {{ .Values.service.restNodePort }} + {{- end }} selector: {{- include "cln.selectorLabels" . | nindent 4 }} diff --git a/resources/charts/bitcoincore/charts/cln/values.yaml b/resources/charts/bitcoincore/charts/cln/values.yaml index 953280445..ae7d1a510 100644 --- a/resources/charts/bitcoincore/charts/cln/values.yaml +++ b/resources/charts/bitcoincore/charts/cln/values.yaml @@ -22,6 +22,10 @@ securityContext: {} service: type: ClusterIP + # NodePorts are only used if service.type is NodePort, values must be in the range 30000-32767 + p2pNodePort: + rpcNodePort: + restNodePort: P2PPort: 9735 RPCPort: 9736 diff --git a/resources/charts/bitcoincore/charts/lnd/templates/service.yaml b/resources/charts/bitcoincore/charts/lnd/templates/service.yaml index aecf301fe..3a7492ad1 100644 --- a/resources/charts/bitcoincore/charts/lnd/templates/service.yaml +++ b/resources/charts/bitcoincore/charts/lnd/templates/service.yaml @@ -12,19 +12,31 @@ spec: targetPort: rpc protocol: TCP name: rpc + {{- if and (eq .Values.service.type "NodePort") (.Values.service.rpcNodePort) }} + nodePort: {{ .Values.service.rpcNodePort }} + {{- end }} - port: {{ .Values.P2PPort }} targetPort: p2p protocol: TCP name: p2p + {{- if and (eq .Values.service.type "NodePort") (.Values.service.p2pNodePort) }} + nodePort: {{ .Values.service.p2pNodePort }} + {{- end }} - port: {{ .Values.RestPort }} targetPort: rest protocol: TCP name: rest + {{- if and (eq .Values.service.type "NodePort") (.Values.service.restNodePort) }} + nodePort: {{ .Values.service.restNodePort }} + {{- end }} {{- if .Values.metricsExport }} - port: {{ .Values.prometheusMetricsPort }} targetPort: prom-metrics protocol: TCP name: prometheus-metrics + {{- if and (eq .Values.service.type "NodePort") (.Values.service.prometheusNodePort) }} + nodePort: {{ .Values.service.prometheusNodePort }} + {{- end }} {{- end }} selector: {{- include "lnd.selectorLabels" . | nindent 4 }} diff --git a/resources/charts/bitcoincore/charts/lnd/values.yaml b/resources/charts/bitcoincore/charts/lnd/values.yaml index a97e9470d..06de17af4 100644 --- a/resources/charts/bitcoincore/charts/lnd/values.yaml +++ b/resources/charts/bitcoincore/charts/lnd/values.yaml @@ -32,6 +32,11 @@ securityContext: {} service: type: ClusterIP + # NodePorts are only used if service.type is NodePort, values must be in the range 30000-32767 + p2pNodePort: + rpcNodePort: + restNodePort: + prometheusNodePort: RPCPort: 10009 P2PPort: 9735 diff --git a/resources/charts/bitcoincore/templates/service.yaml b/resources/charts/bitcoincore/templates/service.yaml index 8d8fa5324..4ca3db641 100644 --- a/resources/charts/bitcoincore/templates/service.yaml +++ b/resources/charts/bitcoincore/templates/service.yaml @@ -12,21 +12,36 @@ spec: targetPort: rpc protocol: TCP name: rpc + {{- if and (eq .Values.service.type "NodePort") (.Values.service.rpcNodePort) }} + nodePort: {{ .Values.service.rpcNodePort }} + {{- end }} - port: {{ index .Values.global .Values.global.chain "P2PPort" }} targetPort: p2p protocol: TCP name: p2p + {{- if and (eq .Values.service.type "NodePort") (.Values.service.p2pNodePort) }} + nodePort: {{ .Values.service.p2pNodePort }} + {{- end }} - port: {{ .Values.global.ZMQTxPort }} targetPort: zmq-tx protocol: TCP name: zmq-tx + {{- if and (eq .Values.service.type "NodePort") (.Values.service.zmqTxNodePort) }} + nodePort: {{ .Values.service.zmqTxNodePort }} + {{- end }} - port: {{ .Values.global.ZMQBlockPort }} targetPort: zmq-block protocol: TCP name: zmq-block + {{- if and (eq .Values.service.type "NodePort") (.Values.service.zmqBlockNodePort) }} + nodePort: {{ .Values.service.zmqBlockNodePort }} + {{- end }} - port: {{ .Values.prometheusMetricsPort }} targetPort: prom-metrics protocol: TCP name: prometheus-metrics + {{- if and (eq .Values.service.type "NodePort") (.Values.service.prometheusNodePort) }} + nodePort: {{ .Values.service.prometheusNodePort }} + {{- end }} selector: {{- include "bitcoincore.selectorLabels" . | nindent 4 }} diff --git a/resources/charts/bitcoincore/values.yaml b/resources/charts/bitcoincore/values.yaml index 92416f6bb..5b8f486b9 100644 --- a/resources/charts/bitcoincore/values.yaml +++ b/resources/charts/bitcoincore/values.yaml @@ -32,6 +32,12 @@ securityContext: {} service: type: ClusterIP + # NodePorts are only used if service.type is NodePort, values must be in the range 30000-32767 + p2pNodePort: + rpcNodePort: + zmqTxNodePort: + zmqBlockNodePort: + prometheusNodePort: ingress: enabled: false