You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/content/guides/traffic_management/destination_types/kubernetes_services/_index.md
+59-9
Original file line number
Diff line number
Diff line change
@@ -4,17 +4,28 @@ weight: 80
4
4
description: Routing to services registered as Kubernetes Services through the API
5
5
---
6
6
7
-
If you are running Gloo Edge in a Kubernetes cluster, it is possible to directly specify
8
-
[Kubernetes Services](https://kubernetes.io/docs/concepts/services-networking/service/) as routing destinations.
9
-
The `kube` destination type has two required fields:
7
+
To allow for optimal performance in Gloo Edge, it is recommended to use Gloo [static]({{% versioned_link_path fromRoot="/guides/traffic_management/destination_types/static_upstream/" %}}) and [discovered]({{% versioned_link_path fromRoot="/guides/traffic_management/destination_types/discovered_upstream/" %}}) Upstreams as your routing destination. However, if you run Gloo Edge in a Kubernetes cluster, you can choose between the following options to route to a Kubernetes service:
10
8
11
-
*`ref` is a {{< protobuf name="core.solo.io.ResourceRef">}} to the service that should receive traffic
12
-
*`port` is an `int` which represents the port on which the service is listening. This must be one of the ports defined in the Kubernetes service spec
9
+
## Option 1: Route to a Kubernetes service directly
13
10
14
-
The following configuration will forward all requests to `/petstore` to port `8080` on the Kubernetes service named
15
-
`petstore` in the `default` namespace.
11
+
You can configure your VirtualService to route to a Kubernetes service instead of a Gloo Upstream.
16
12
17
-
{{< highlight yaml "hl_lines=6-10" >}}
13
+
{{% notice note %}}
14
+
Consider the following information before choosing a Kubernetes service as your routing destination:
15
+
- For Gloo Edge to route traffic to a Kubernetes service directly, Gloo Edge requires scanning of all services in the cluster to create in-memory Upstream resources to represent them. Gloo uses these resources to validate that the upstream destination is valid and returns an error if the specified Kubernetes service cannot be found. Note that the in-memory Upstream resources are included in the API snapshot. If you have a large number of services in your cluster, the API snapshot increases which can have a negative impact on the Gloo Edge translation time.
16
+
- When using Kubernetes services as a routing destination, Gloo Edge relies on `kube-proxy` to perform load balancing which can have further performance impacts. Routing to Gloo Upstreams bypasses `kube-proxy` as the request is routed to the pod directly.
17
+
- Some Gloo Edge functionality, such as policies, might not be available when using Kubernetes services as a routing destination.
18
+
{{% /notice %}}
19
+
20
+
To use Kubernetes services as a routing destination:
21
+
22
+
1. Get the default Gloo Edge settings and verify that `spec.gloo.disableKubernetesDestinations` is set to `false`. This setting is required to allow Gloo Edge to scan all Kubernetes services in the cluster and to create in-memory Upstream resources to represent them. If it is set to `true`, follow the [upgrade guide]({{% versioned_link_path fromRoot="/operations/upgrading/" %}}) and set `settings.disableKubernetesDestinations: false` in your Helm chart.
23
+
```sh
24
+
kubectl get settings default -n gloo-system -o yaml
25
+
```
26
+
2. Configure the Kubernetes service as a routing destination in your VirtualService. The following example configuration forwards all requests to `/petstore` to port `8080` on the `petstore` Kubernetes service in the `default` namespace.
27
+
28
+
{{< highlight yaml "hl_lines=6-10" >}}
18
29
routes:
19
30
- matchers:
20
31
- prefix: /petstore
@@ -25,4 +36,43 @@ routes:
25
36
name: petstore
26
37
namespace: default
27
38
port: 8080
28
-
{{< /highlight >}}
39
+
{{< /highlight >}}
40
+
41
+
The `kube` destination type has two required fields:
42
+
43
+
*`ref` is a {{< protobuf name="core.solo.io.ResourceRef">}} to the service that receives the traffic.
44
+
*`port` is an integer (`int`) and represents the port the service listens on. Note that this port must be defined in the Kubernetes service.
45
+
46
+
47
+
## Option 2: Use Kubernetes Upstream resources
48
+
49
+
Instead of routing to a Kubernetes service directly, you can create [Gloo Kubernetes Upstream]({{% versioned_link_path fromRoot="/reference/api/github.com/solo-io/gloo/projects/gloo/api/v1/options/kubernetes/kubernetes.proto.sk/" %}}) resources that represent your Kubernetes workload. With Kubernetes Upstream resources, you can route requests to a specific pod in the cluster. This process bypasses `kube-proxy` which improves load balancing times for your workloads.
50
+
51
+
To use Kubernetes Upstream resources:
52
+
53
+
1. Create a Kubernetes Upstream resource for your workload. The following configuration creates an upstream resource for the Petstore app that listens on port 8080 in the default namespace.
54
+
```yaml
55
+
apiVersion: gloo.solo.io/v1
56
+
kind: Upstream
57
+
metadata:
58
+
name: petstore
59
+
namespace: gloo-system
60
+
spec:
61
+
kube:
62
+
serviceName: petstore
63
+
serviceNamespace: default
64
+
servicePort: 8080
65
+
```
66
+
67
+
2. Configure the Kubernetes Upstream as a routing destination in your VirtualService. The following example configuration forwards all requests to `/petstore` to the Petstore upstream in the `gloo-system` namespace.
0 commit comments