A DNAT Service provides Network Address Translation (NAT) for all nodes in a cluster so that multiple nodes can share an EIP. The access address of a DNAT Service is in the format of <EIP-of-the-NAT-gateway>:<access-port>, for example, 10.117.117.117:80.
If pods require temporary access from the Internet or the traffic is low, you can create a DNAT Service. DNAT Services provide higher reliability than NodePort Services. With a DNAT Service, there is no need to bind an EIP to a single node, and requests can still be distributed to the workload even any of the nodes inside is down.
Figure 1 DNAT Service

Observe the following constraints when using the NAT Gateway service:
You have purchased a NAT gateway and an EIP. The specific procedure is as follows:
After purchasing a NAT gateway, you do not need to add SNAT or DNAT rules.
When purchasing a NAT gateway, ensure that the NAT gateway belongs to the same VPC and subnet as the CCE cluster where the workload is running.
Parameter | Description |
|---|---|
Service Name | Enter a name, which can be the same as the workload name. |
Service Type | Select DNAT. |
Namespace | Select the namespace that the workload belongs to. |
Service Affinity | Whether to route external traffic to a local node or a cluster-wide endpoint. For details, see Service Affinity (externalTrafficPolicy).
|
Selector | The Service will be associated with the workload pods based on the label and direct traffic to the pods with this label. You can add a key and value for the pod label and click Confirm. You can also click Reference Workload Label to use the label of an existing workload. In the dialog box displayed, select a workload and click OK. |
DNAT | Select the DNAT gateway and EIP purchased in Preparations: Creating a NAT Gateway and an EIP. |
Port |
|
You can configure Service access when creating a workload using kubectl. This section uses an Nginx workload as an example to describe how to implement intra-cluster access using kubectl.
vi nginx-deployment.yaml
File content:
apiVersion: apps/v1kind: Deploymentmetadata:name: nginxspec:replicas: 1selector:matchLabels:app: nginxtemplate:metadata:labels:app: nginxspec:containers:- image: nginx:latestname: nginximagePullSecrets:- name: default-secret
vi nginx-nodeport-svc.yaml
File content:
apiVersion: v1kind: Servicemetadata:name: nginx-natannotations:kubernetes.io/elb.class: dnatkubernetes.io/natgateway.id: e4a1cfcf-29df-4ab8-a4ea-c05dc860f554spec:loadBalancerIP: 10.78.42.242ports:- name: service0port: 80protocol: TCPtargetPort: 80selector:app: nginxtype: LoadBalancer
Parameter | Mandatory | Type | Description |
|---|---|---|---|
kubernetes.io/elb.class | Yes | String | This parameter is set to dnat, which is used to access the NAT Gateway service and add DNAT rules. This parameter cannot be modified after the resource is created. |
kubernetes.io/natgateway.id | Yes | String | ID of a NAT gateway. This parameter cannot be modified after the resource is created. How to obtain: On the management console, click Service List and choose Networking > NAT Gateway. Click the name of the target NAT gateway to access its details page. On the Basic Information tab, find and copy the ID. |
loadBalancerIP | Yes | String | Enter the EIP associated with the NAT gateway. |
port | Yes | Integer | The port used to access the DNAT Service. You can customize the port as required. The port ranges from 1 to 65535. |
targetPort | Yes | String | The listening port of the service containers. The port ranges from 1 to 65535. You need to determine the port based on the container image. For example, the default port of Nginx is 80, and the default port of MySQL is 3306. |
type | Yes | String | NAT gateway service type must be set to LoadBalancer. |
kubectl create -f nginx-deployment.yaml
If information similar to the following is displayed, the workload has been created:
deployment/nginx created
Check the created workload.
kubectl get pod
If information similar to the following is displayed, the workload is running:
NAME READY STATUS RESTARTS AGEnginx-2601814895-znhbr 1/1 Running 0 15s
kubectl create -f nginx-nat-svc.yaml
If information similar to the following is displayed, the Service is being created:
service/nginx-nat created
Check the created Service.
kubectl get svc
If information similar to the following is displayed, the Service has been created:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEkubernetes ClusterIP 10.247.0.1 <none> 443/TCP 3dnginx-nat LoadBalancer 10.247.226.2 **.**.**.** 80:30589/TCP 5s
