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
title: Deploy self-hosted gateway to Kubernetes | Microsoft Docs
3
-
description: Learn how to deploy self-hosted gateway component of Azure API Management to Kubernetes
2
+
title: Deploy a self-hosted gateway to Kubernetes | Microsoft Docs
3
+
description: Learn how to deploy a self-hosted gateway component of Azure API Management to Kubernetes
4
4
services: api-management
5
5
author: vladvino
6
6
manager: gwallace
@@ -10,104 +10,108 @@ ms.topic: article
10
10
ms.author: apimpm
11
11
ms.date: 04/23/2020
12
12
---
13
-
# Deploy self-hosted gateway to Kubernetes
13
+
# Deploy a self-hosted gateway to Kubernetes
14
14
15
-
This article describes the steps for deploying self-hosted gateway component of Azure API Management to a Kubernetes cluster.
15
+
This article describes the steps for deploying the self-hosted gateway component of Azure API Management to a Kubernetes cluster.
16
16
17
17
## Prerequisites
18
18
19
-
- Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md)
19
+
- Complete the following quickstart: [Create an Azure API Management instance](get-started-create-service-instance.md).
20
20
- Create a Kubernetes cluster.
21
-
> [!TIP]
22
-
> [Single-node clusters](https://kubernetes.io/docs/setup/#learning-environment) work well for development and evaluation purposes. Use [Kubernetes Certified](https://kubernetes.io/partners/#conformance) multi-node clusters on-premises or in the cloud for production workloads.
21
+
> [!TIP]
22
+
> [Single-node clusters](https://kubernetes.io/docs/setup/#learning-environment) work well for development and evaluation purposes. Use [Kubernetes Certified](https://kubernetes.io/partners/#conformance) multi-node clusters on-premises or in the cloud for production workloads.
23
23
-[Provision a self-hosted gateway resource in your API Management instance](api-management-howto-provision-self-hosted-gateway.md).
24
24
25
25
## Deploy to Kubernetes
26
26
27
-
1. Select **Gateways**from under **Deployment and infrastructure**.
28
-
2. Select the self-hosted gateway resource you intend to deploy.
27
+
1. Select **Gateways** under **Deployment and infrastructure**.
28
+
2. Select the self-hosted gateway resource that you want to deploy.
29
29
3. Select **Deployment**.
30
-
4.Note that an access token in the **Token** text box was autogenerated for you using the default **Expiry** and **Secret key** values. If needed, pick desired values in either or both controls to generate a new token.
31
-
5. Select **Kubernetes** tab under **Deployment scripts**.
32
-
6.Click on the **<gateway-name>.yml** file link and download the YAML file.
33
-
7. Select **copy** icon located at the bottom right corner of the **Deploy** text box to save the `kubectl` commands to the clipboard.
34
-
8. Paste commands to the terminal (or command) window. The first command creates a Kubernetes secret containing access token generated in step 4. Second command applies the configuration file downloaded in step 6 to the Kubernetes cluster and expects the the file to be present in the current directory.
35
-
9.Execute the commands to create the necessary Kubernetes objects in the [default namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) and start self-hosted gateway pod(s) from [container image](https://aka.ms/apim/sputnik/dhub) downloaded from the Microsoft Container Registry.
36
-
10.Execute command shown bellow to check if the deployment succeeded. Note that it might take a little time for all the objects to be created and for pod(s) to initialize.
37
-
```console
38
-
kubectl get deployments
39
-
NAME READY UP-TO-DATE AVAILABLE AGE
40
-
<gateway-name> 1/1 1 1 18s
41
-
```
42
-
11.Execute command shown bellow to check if the service was successfully created. Note that your service IPs and ports will be different.
4.An access token in the **Token** text box was autogenerated for you, based on the default **Expiry** and **Secret key** values. If needed, choose values in either or both controls to generate a new token.
31
+
5. Select the **Kubernetes** tab under **Deployment scripts**.
32
+
6.Select the **<gateway-name>.yml** file link and download the YAML file.
33
+
7. Select the **copy** icon at the lower-right corner of the **Deploy** text box to save the `kubectl` commands to the clipboard.
34
+
8. Paste commands to the terminal (or command) window. The first command creates a Kubernetes secret that contains the access token generated in step 4. The second command applies the configuration file downloaded in step 6 to the Kubernetes cluster and expects the file to be in the current directory.
35
+
9.Run the commands to create the necessary Kubernetes objects in the [default namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) and start self-hosted gateway pods from the[container image](https://aka.ms/apim/sputnik/dhub) downloaded from the Microsoft Container Registry.
36
+
10.Run the following command to check if the deployment succeeded. Note that it might take a little time for all the objects to be created and for the pods to initialize.
37
+
```console
38
+
kubectl get deployments
39
+
NAME READY UP-TO-DATE AVAILABLE AGE
40
+
<gateway-name> 1/1 1 1 18s
41
+
```
42
+
11. Run the following command to check if the service was successfully created. Note that your service IPs and ports will be different.
12. Go back to the Azure portal and select **Overview**.
49
-
13.**Status**showing a green checkmark icon followed by the node count matching the number of replicas specified in the YAML file confirms that deployed self-hosted gateway pods are successfully communicating with the API Management service and have a regular "heartbeat".
49
+
13. Confirm that **Status** shows a green check mark, followed by a node count that matches the number of replicas specified in the YAML file. This status means the deployed self-hosted gateway pods are successfully communicating with the API Management service and have a regular "heartbeat."
> Execute <code>kubectl logs deployment/<gateway-name></code> command to view logs from a randomly selected pod if there are more than one.
55
-
> Execute <code>kubectl logs -h</code> for a complete set of command options, e.g. how to view logs for a specific pod or container.
54
+
> Run the <code>kubectl logs deployment/<gateway-name></code>command to view logs from a randomly selected pod if there's more than one.
55
+
> Run<code>kubectl logs -h</code>for a completeset of command options, such as how to view logs for a specific pod or container.
56
56
57
57
## Production deployment considerations
58
58
59
59
### Access token
60
-
Without a valid access token self-hosted gateway is unable to access and download configuration from configuration data endpoint of the associated API Management service. Access token can be valid for a maximum of 30 days. It must be regenerated and the cluster configured with a fresh token either manually or via automation before it expires. When automating token refresh use this management API [operation](https://docs.microsoft.com/rest/api/apimanagement/2019-12-01/gateway/generatetoken) to generated a new token. Follow this [link](https://kubernetes.io/docs/concepts/configuration/secret) for information on managing Kubernetes secrets.
60
+
Without a valid access token, a self-hosted gateway can't access and download configuration data from the endpoint of the associated API Management service. The access token can be valid for a maximum of 30 days. It must be regenerated, and the cluster configured with a fresh token, either manually or via automation before it expires.
61
+
62
+
When you're automating token refresh, use [this management API operation](https://docs.microsoft.com/rest/api/apimanagement/2019-12-01/gateway/generatetoken) to generate a new token. For information on managing Kubernetes secrets, see the [Kubernetes website](https://kubernetes.io/docs/concepts/configuration/secret).
61
63
62
64
### Namespace
63
-
Kubernetes [namespaces](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) help with dividing a single cluster among multiple teams, projects, or applications. Namespaces provide a scope for resources and names and can be associated with a resource quota and access control policies.
64
-
Commands provided in the Azure portal create self-hosted gateway resources in the **default** namespace which is automatically created, exists in every cluster, and can't be deleted.
65
-
Consider [creating and deploying](https://kubernetesbyexample.com/ns/) self-hosted gateway into a separate namespace in production.
65
+
Kubernetes [namespaces](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/) help with dividing a single cluster among multiple teams, projects, or applications. Namespaces provide a scope for resources and names. They can be associated with a resource quota and access control policies.
66
+
67
+
The Azure portal provides commands to create self-hosted gateway resources in the **default** namespace. This namespace is automatically created, exists in every cluster, and can't be deleted.
68
+
Consider [creating and deploying](https://kubernetesbyexample.com/ns/) a self-hosted gateway into a separate namespace in production.
66
69
67
70
### Number of replicas
68
-
Minimal number of replicas suitable in production is two.
71
+
The minimum number of replicas suitable for production is two.
69
72
70
-
By default, self-hosted gateway is deployed with a **RollingUpdate** deployment [strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy). Review the default values and consider explicitly setting [**maxUnavailable**](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-unavailable) and [**maxSurge**](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-surge) fields, especially when using a high replica count.
73
+
By default, a self-hosted gateway is deployed with a **RollingUpdate** deployment [strategy](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy). Review the default values and consider explicitly setting the [maxUnavailable](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-unavailable) and [maxSurge](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#max-surge) fields, especially when you're using a high replica count.
71
74
72
75
### Container resources
73
76
By default, the YAML file provided in the Azure portal doesn't specify container resource requests.
74
77
75
-
It's impossible to reliably predict and recommend the amount of per-container CPU and memory resources and the number of replicas required for supporting a specific workload due to many factors at play, e.g.:
78
+
It's impossible to reliably predict and recommend the amount of per-container CPU and memory resources and the number of replicas required for supporting a specific workload. Many factors are at play, such as:
76
79
77
-
- Specific hardware the cluster is running on
78
-
- Presence and type of virtualization
79
-
- Number and rate of concurrent client connections
80
-
- Request rate
81
-
- Kind and number of configured policies
82
-
- Payload size and if payloads are buffered or streamed
83
-
- Backend service latency
80
+
- Specific hardware that the cluster is running on.
81
+
- Presence and type of virtualization.
82
+
- Number and rate of concurrent client connections.
83
+
- Request rate.
84
+
- Kind and number of configured policies.
85
+
- Payload size and whether payloads are buffered or streamed.
86
+
- Backend service latency.
84
87
85
-
We recommend setting resource request to 2 cores and 2 GiB as a starting point, performing a load test and scaling up/out or down/in based the results.
88
+
We recommend setting resource requests to two cores and 2 GiB as a starting point. Perform a load test and scale up/out or down/in based on the results.
86
89
87
90
### Container image tag
88
-
The YAML file provided in the Azure portal uses the **latest** tag which always references the most recent version of the self-hosted gateway container image.
91
+
The YAML file provided in the Azure portal uses the **latest** tag. This tag always references the most recent version of the self-hosted gateway container image.
89
92
90
93
Consider using a specific version tag in production to avoid unintentional upgrade to a newer version.
91
94
92
-
Follow this [link](https://mcr.microsoft.com/v2/azure-api-management/gateway/tags/list) to see the full list of available tags.
95
+
You can [download a full list of available tags](https://mcr.microsoft.com/v2/azure-api-management/gateway/tags/list).
93
96
94
97
### DNS policy
95
-
DNS name resolution plays a critical role in self-hosted gateway's ability to connect to dependencies in Azure and dispatch API calls to backend services.
98
+
DNS name resolution plays a critical role in a self-hosted gateway's ability to connect to dependencies in Azure and dispatch API calls to backend services.
96
99
97
-
The YAML file provided in the Azure portal applies the default [**ClusterFirst**](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy) policy which causes name resolution requests not resolved by the cluster DNS to be forwarded to the upstream DNS server inherited from the node.
100
+
The YAML file provided in the Azure portal applies the default [ClusterFirst](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy) policy. This policy causes name resolution requests not resolved by the cluster DNS to be forwarded to the upstream DNS server that's inherited from the node.
98
101
99
-
Follow this [link](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service) to learn about name resolution in Kubernetes and consider customizing [DNS policy](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy) or D[NS configuration](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-config) as appropriate for your setup.
102
+
To learn about name resolution in Kubernetes, see the [Kubernetes website](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service). Consider customizing [DNS policy](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy) or [DNS configuration](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-config) as appropriate for your setup.
100
103
101
104
### Configuration backup
102
-
Follow this [link](self-hosted-gateway-overview.md#connectivity-to-azure) to learn about self-hosted gateway behavior in the presence of a temporary Azure connectivity outage.
103
-
Configure local storage volume for the self-hosted gateway container, so it can persist a backup copy of the latest downloaded configuration and, if connectivity is down, use it upon restart. The volume mount path must be <code>/apim/config</code>. See an example [here](https://github.com/Azure/api-management-self-hosted-gateway/blob/master/examples/self-hosted-gateway-with-configuration-backup.yaml).
104
-
To learn about storage in Kubernetes follow this [link](https://kubernetes.io/docs/concepts/storage/volumes/).
105
+
To learn about self-hosted gateway behavior in the presence of a temporary Azure connectivity outage, see [Self-hosted gateway overview](self-hosted-gateway-overview.md#connectivity-to-azure).
106
+
107
+
Configure a local storage volume for the self-hosted gateway container, so it can persist a backup copy of the latest downloaded configuration. If connectivity is down, the storage volume can use the backup copy upon restart. The volume mount path must be <code>/apim/config</code>. See an example on [GitHub](https://github.com/Azure/api-management-self-hosted-gateway/blob/master/examples/self-hosted-gateway-with-configuration-backup.yaml).
108
+
To learn about storage in Kubernetes, see the [Kubernetes website](https://kubernetes.io/docs/concepts/storage/volumes/).
105
109
106
110
### Local logs and metrics
107
-
Self-hosted gateway sends telemetry to [Azure Monitor](api-management-howto-use-azure-monitor.md) and [Azure Application Insights](api-management-howto-app-insights.md)per configuration settings in the associated API Management service.
111
+
The self-hosted gateway sends telemetry to [Azure Monitor](api-management-howto-use-azure-monitor.md) and [Azure Application Insights](api-management-howto-app-insights.md) according to configuration settings in the associated API Management service.
108
112
When [connectivity to Azure](self-hosted-gateway-overview.md#connectivity-to-azure) is temporarily lost, the flow of telemetry to Azure is interrupted and the data is lost for the duration of the outage.
109
-
Consider [setting up local monitoring](how-to-configure-local-metrics-logs.md) to ensure ability to observe the API traffic and prevent telemetry loss during Azure connectivity outages.
113
+
Consider [setting up local monitoring](how-to-configure-local-metrics-logs.md) to ensure the ability to observe API traffic and prevent telemetry loss during Azure connectivity outages.
110
114
111
115
## Next steps
112
116
113
-
* To learn more about the self-hosted gateway, see [Azure API Management self-hosted gateway overview](self-hosted-gateway-overview.md)
117
+
* To learn more about the self-hosted gateway, see [Self-hosted gateway overview](self-hosted-gateway-overview.md).
0 commit comments