mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-09-24 20:18:18 +00:00
Fixes for Expose Your Services
This commit is contained in:
committed by
Denise
parent
325d729d78
commit
3e6ddcb68c
@@ -17,10 +17,10 @@ Use this document to correct workloads that list `ports` in `output.txt`. You ca
|
||||
<!-- TOC -->
|
||||
|
||||
- [What's Different About Exposing Services in Rancher v2.x?](#what-s-different-about-exposing-services-in-rancher-v2-x)
|
||||
- [HostPorts](#hostports)
|
||||
- [Setting HostPorts](#setting-hostports)
|
||||
- [NodePorts](#nodeports)
|
||||
- [Setting NodePorts](#setting-nodeports)
|
||||
- [HostPorts](#hostport)
|
||||
- [Setting HostPort](#setting-hostport)
|
||||
- [NodePorts](#nodeport)
|
||||
- [Setting NodePort](#setting-nodeport)
|
||||
|
||||
<!-- /TOC -->
|
||||
|
||||
@@ -30,9 +30,9 @@ In Rancher v1.6, we used the term _Port Mapping_ for exposing an IP address and
|
||||
|
||||
In Rancher v2.x, the mechanisms and terms for service exposure have changed and expanded. You now have two port mapping options: _HostPorts_ (which is most synonymous with v1.6 port mapping, allows you to expose your app at a single IP and port) and _NodePorts_ (which allows you to map ports on _all_ of your cluster nodes, not just one).
|
||||
|
||||
Unfortunately, port mapping cannot be parsed by the migration-tools CLI. If the services you're migrating from v1.6 to v2.x have port mappings set, you'll have to either set a [HostPort](#hostports) or [NodePort](#nodeports) as a replacement.
|
||||
Unfortunately, port mapping cannot be parsed by the migration-tools CLI. If the services you're migrating from v1.6 to v2.x have port mappings set, you'll have to either set a [HostPort](#hostport) or [NodePort](#nodeport) as a replacement.
|
||||
|
||||
## HostPorts
|
||||
## HostPort
|
||||
|
||||
A _HostPort_ is a port exposed to the public on a _specific node_ running one or more pod. Traffic to the node and the exposed port (`<HOST_IP>:<HOSTPORT>`) are routed to the requested container's private port. Using a HostPort for a Kubernetes pod in Rancher v2.x is synonymous with creating a public port mapping for a container in Rancher v1.6.
|
||||
|
||||
@@ -53,7 +53,7 @@ In the following diagram, a user is trying to access an instance of Nginx, which
|
||||
- Any two workloads that specify the same HostPort cannot be deployed to the same node.
|
||||
- If the host where your pods are running becomes unavailable, Kubernetes reschedules the pods to different nodes. Thus, if the IP address for your workload changes, external clients of your application will lose access to the pod. The same thing happens when you restart your pods—Kubernetes reschedules them to a different node.
|
||||
|
||||
## Setting HostPorts
|
||||
## Setting HostPort
|
||||
|
||||
You can set a HostPort for migrated workloads (i.e., services) using the Rancher v2.x UI. To add a HostPort, browse to the project containing your workloads, and edit each workload that you want to expose, as shown below. Map the port that your service container exposes to the HostPort exposed on your target node.
|
||||
|
||||
@@ -63,67 +63,7 @@ For example, for the web-deployment.yml file parsed from v1.6 that we've been us
|
||||
|
||||

|
||||
|
||||
|
||||
<!--
|
||||
{{% tabs %}}
|
||||
{{% tab "Migrated Workload" %}}
|
||||
While parsing Compose files to Kubernetes manifest, our migration-tool does not convert Rancher v1.6 port mappings to v2.x HostPorts. If you want to set a HostPort to expose one of the deployments you're migrating (not services), you'll have to manually add it to the [parsed Kubernetes manifest]({{< baseurl >}}/rancher/v2.x/en/v1.6-migration/run-migration-tool/#output), as displayed in the sample below.
|
||||
|
||||
In this sample, we've taken the [web-deployment.yml]({{< baseurl >}}/rancher/v2.x/en/v1.6-migration/run-migration-tool/#migration-example-file-output) file parsed from [docker-compose.yml]({{< baseurl >}}/rancher/v2.x/en/v1.6-migration/run-migration-tool/#migration-example-files) specified for Let's Chat.
|
||||
|
||||
<figcaption>HostPort Kubernetes manifest Example: <code>web-deployment.yaml</code></figcaption>
|
||||
|
||||
```YAML
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
io.rancher.container.pull_image: always
|
||||
io.rancher.scheduler.global: "true"
|
||||
kompose.cmd: ./migration-tools parse --docker-file docker-compose.yml --rancher-file
|
||||
rancher-compose.yml
|
||||
kompose.version: 1.16.0 ()
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: web
|
||||
name: web
|
||||
spec:
|
||||
replicas: 0
|
||||
strategy: {}
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: web
|
||||
spec:
|
||||
containers:
|
||||
- image: sdelements/lets-chat
|
||||
name: web
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
hostPort: 9890 # NEW HOSTPORT DECLARATION
|
||||
resources: {}
|
||||
stdin: true
|
||||
tty: true
|
||||
restartPolicy: Always
|
||||
status: {}
|
||||
|
||||
```
|
||||
{{% /tab %}}
|
||||
{{% tab "New Workload" %}}
|
||||
|
||||
While creating a new workload using the Rancher v2.x UI, you may specify a HostPort in the **Port Mapping** section. This action adds a `hostPort` value to the `ports` section of the cluster's Kubernetes manifest automatically. For more information on using Rancher UI to set a HostPort for a workload, see [Deploying Workloads]({{< baseurl >}}/rancher/v2.x/en/k8s-in-rancher/workloads/deploy-workloads/).
|
||||
|
||||
<figcaption>Workload Deployment: Setting HostPort</figcaption>
|
||||
|
||||

|
||||
|
||||
{{% /tab %}}
|
||||
{{% /tabs %}}
|
||||
|
||||
-->
|
||||
|
||||
## NodePorts
|
||||
## NodePort
|
||||
|
||||
A _NodePort_ is a port that's open to the public _on each_ of your cluster nodes. When the NodePort receives a request for any of the cluster hosts' IP address for the set NodePort value, NodePort (which is a Kubernetes service) routes traffic to a specific pod, regardless of what node it's running on. NodePort provides a static endpoint where external requests can reliably reach your pods.
|
||||
|
||||
@@ -133,8 +73,7 @@ In the following diagram, a user is trying to connect to an instance of Nginx ru
|
||||
|
||||

|
||||
|
||||
NodePorts are available within your Kubernetes cluster on an internal IP. If you want to expose pods external to the cluster, use NodePorts in conjunction with an external load balancer. Traffic requests from outside your cluster for `<NodeIP>:<NodePort>` are directed to the workload by kube-proxy. The `<NodeIP>` can be the IP address of any node in your Kubernetes cluster.
|
||||
|
||||
NodePorts are available within your Kubernetes cluster on an internal IP. If you want to expose pods external to the cluster, use NodePorts in conjunction with an external load balancer. Traffic requests from outside your cluster for `<NodeIP>:<NodePort>` are directed to the workload. The `<NodeIP>` can be the IP address of any node in your Kubernetes cluster.
|
||||
|
||||
#### NodePort Pros
|
||||
|
||||
@@ -144,15 +83,14 @@ NodePorts are available within your Kubernetes cluster on an internal IP. If you
|
||||
#### NodePort Cons
|
||||
|
||||
- When a NodePort is used, that `<NodeIP>:<NodePort>` is reserved in your Kubernetes cluster on all nodes, even if the workload is never deployed to the other nodes.
|
||||
- You can only specify a port from the configured range (`30000-32767`) and not any random port.
|
||||
- You can only specify a port from a configurable range (by default, it is `30000-32767`).
|
||||
- An extra Kubernetes object (a Kubernetes service of type NodePort) is needed to expose your workload. Thus, finding out how your application is exposed is not straightforward.
|
||||
|
||||
|
||||
## Setting NodePorts
|
||||
## Setting NodePort
|
||||
|
||||
You can set a NodePort for migrated workloads (i.e., services) using the Rancher v2.x UI. To add a NodePort, browse to the project containing your workloads, and edit each workload that you want to expose, as shown below. Map the port that your service container exposes to a NodePort, which you'll be able to access from each cluster node.
|
||||
|
||||
For example, for the web-deployment.yml file parsed from v1.6 that we've been using as a sample, we would edit its Kubernetes manifest, set the publish the port that the container uses, and then declare a NodePort. You can then access your workload by clicking the link created in the Rancher UI.
|
||||
For example, for the `web-deployment.yml` file parsed from v1.6 that we've been using as a sample, we would edit its Kubernetes manifest, set the publish the port that the container uses, and then declare a NodePort. You can then access your workload by clicking the link created in the Rancher UI.
|
||||
|
||||
>**Note:**
|
||||
>
|
||||
@@ -163,70 +101,4 @@ For example, for the web-deployment.yml file parsed from v1.6 that we've been us
|
||||
|
||||

|
||||
|
||||
|
||||
<!--
|
||||
|
||||
{{% tabs %}}
|
||||
{{% tab "Migrated Workload" %}}
|
||||
|
||||
You can declare a NodePort for a workload that you're migrating by editing its Kubernetes manifest. In this sample, we've taken the same [web-deployment.yml]({{< baseurl >}}/rancher/v2.x/en/v1.6-migration/run-migration-tool/#migration-example-file-output) referenced in [Setting HostPorts](#setting-hostports). However, in this manifest, we've set a NodePort instead of a HostPort.
|
||||
|
||||
>**Note:**
|
||||
>
|
||||
>- If you set the `nodePort` directive without giving it a value, Rancher chooses a port at random from the following range: `30000-32767`.
|
||||
>- If you manually set the `nodePort` directive, you must assign it a value within the `30000-32767` range.
|
||||
|
||||
<figcaption>HostPort Kubernetes manifest Example: <code>web-deployment.yaml</code></figcaption>
|
||||
|
||||
```YAML
|
||||
apiVersion: extensions/v1beta1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
io.rancher.container.pull_image: always
|
||||
io.rancher.scheduler.global: "true"
|
||||
kompose.cmd: ./migration-tools parse --docker-file docker-compose.yml --rancher-file
|
||||
rancher-compose.yml
|
||||
kompose.version: 1.16.0 ()
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: web
|
||||
name: web
|
||||
spec:
|
||||
replicas: 0
|
||||
strategy: {}
|
||||
template:
|
||||
metadata:
|
||||
creationTimestamp: null
|
||||
labels:
|
||||
io.kompose.service: web
|
||||
spec:
|
||||
containers:
|
||||
- image: sdelements/lets-chat
|
||||
name: web
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
nodePort: 32767 # NEW NODEPORT DECLARATION
|
||||
resources: {}
|
||||
stdin: true
|
||||
tty: true
|
||||
restartPolicy: Always
|
||||
status: {}
|
||||
|
||||
```
|
||||
|
||||
{{% /tab %}}
|
||||
{{% tab "New Workload" %}}
|
||||
|
||||
|
||||
|
||||
While creating or editing a workload using the Rancher v2.x UI, you may specify a NodePort in the **Port Mapping** section. This action adds a `nodePort` value to the `ports` section of the cluster's Kubernetes manifest automatically. For more information on using Rancher UI to set a NodePort for a workload, see [Deploying Workloads]({{< baseurl >}}/rancher/v2.x/en/k8s-in-rancher/workloads/deploy-workloads/).
|
||||
|
||||
<figcaption>Workload Deployment: Setting NodePort</figcaption>
|
||||
|
||||

|
||||
|
||||
{{% /tab %}}
|
||||
{{% /tabs %}} -->
|
||||
|
||||
### [Next: Configure Health Checks]({{< baseurl >}}/rancher/v2.x/en/v1.6-migration/monitor-apps)
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 11 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 87 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
Reference in New Issue
Block a user