|
| 1 | +HDFS namenode topology plugins for various Kubernetes network providers. |
| 2 | + |
| 3 | +HDFS namenode handles RPC requests from clients. Namenode often gets the IP |
| 4 | +addresses of clients from the remote endpoints of RPC connections. |
| 5 | +In Kubernetes, HDFS clients may run inside pods. The client IP addresses can |
| 6 | +be virtual pod IP addresses. This can confuse the namenode when it runs |
| 7 | +the data locality optimization code, which requires the comparison of client |
| 8 | +IP addresses against the IP addresses associated with datanodes. The latter |
| 9 | +are physical IP addresses of cluster nodes that datanodes are running on. |
| 10 | +The client pod virtual IP addresses would not match any datanode IP addresses. |
| 11 | + |
| 12 | +We can configure namenode with the topology plugins in this directory to |
| 13 | +correct the namenode data locality code. So far, we learned that only |
| 14 | +Google Container Engine (GKE) suffers from the data locality issue caused |
| 15 | +by the virtual pod IP addresses exposed to namenode. (See below) |
| 16 | +GKE uses the native `kubenet` network provider. |
| 17 | + |
| 18 | + - TODO: Currently, there is no easy way to launch the namenode helm chart |
| 19 | + with a topology plugins configured. Build a new Docker image with |
| 20 | + topology plugins and support the configuration. See plugin README |
| 21 | + for installation/configuration instructions. |
| 22 | + |
| 23 | +Many K8s network providers do not need any topology plugins. Most K8s network |
| 24 | +providers conduct IP masquerading or Network Address Translation (NAT), when pod |
| 25 | +packets head outside the pod IP subnet. They rewrite headers of pod packets by |
| 26 | +putting the physical IP addresses of the cluster nodes that pods are running on. |
| 27 | +The namenode and datanodes use `hostNetwork` and their IP addresses are outside |
| 28 | +the pod IP subnet. As the result, namenode will see the physical cluster node |
| 29 | +IP address from client RPC connections originating from pods. The data locality |
| 30 | +will work fine with them. |
| 31 | + |
| 32 | +Here is the list of network providers that conduct NAT: |
| 33 | + |
| 34 | + - By design, overlay networks such as weave and flannel conduct NAT for any |
| 35 | + pod packet heading outside a local pod network. This means packets coming to |
| 36 | + a node IP also does NAT. (In overlay, pod packets heading to another pod in |
| 37 | + a different node puts back the pod IPs once they got inside the destination |
| 38 | + node) |
| 39 | + - Calico is a popular non-overlay network provider. It turns out Calico can be |
| 40 | + also configured to do NAT between pod subnet and node subnet thanks to the |
| 41 | + `nat-outgoing` option. The option can be easily turned on and is enabled |
| 42 | + by default. |
| 43 | + - In EC2, the standard tool kops can provision k8s clusters using the same |
| 44 | + native kubenet that GKE uses. Unlike GKE, it turns out kubenet in EC2 does |
| 45 | + NAT between pod subnet to host network. This is because kops sets option |
| 46 | + --non-masquerade-cidr=100.64.0.0/10 to cover only pod IP subnet. Traffic to |
| 47 | + IPs ouside this range will do NAT. In EC2, cluster hosts like 172.20.47.241 |
| 48 | + sits outside this CIDR. This means pod packets heading to node IPs will do |
| 49 | + masquerading. (Note GKE kubenet uses the default value of |
| 50 | + --non-masquerade-cidr, 10.0.0.0/8, which covers both pod IP and node IP |
| 51 | + subnets. GKE does not expose any way to override this value) |
| 52 | + |
| 53 | +Over time, we will also check the behaviors of other network providers and |
| 54 | +document them here. |
| 55 | + |
| 56 | +Here's how one can check if data locality in the namenode works. |
| 57 | + 1. Launch a HDFS client pod and go inside the pod. |
| 58 | + ``` |
| 59 | + $ kubectl run -i --tty hadoop --image=uhopper/hadoop:2.7.2 \ |
| 60 | + --generator="run-pod/v1" --command -- /bin/bash |
| 61 | + ``` |
| 62 | + 2. Inside the pod, create a simple text file on HDFS. |
| 63 | + ``` |
| 64 | + $ hadoop fs \ |
| 65 | + -fs hdfs://hdfs-namenode-0.hdfs-namenode.default.svc.cluster.local \ |
| 66 | + -cp file:/etc/hosts /hosts |
| 67 | + ``` |
| 68 | + 3. Set the number of replicas for the file to the number of your cluster |
| 69 | + nodes. This ensures that there will be a copy of the file in the cluster node |
| 70 | + that your client pod is running on. Wait some time until this happens. |
| 71 | + ``` |
| 72 | + $ hadoop fs -setrep NUM-REPLICAS /hosts |
| 73 | + ``` |
| 74 | + 4. Run the following `hdfs cat` command. From the debug messages, see |
| 75 | + which datanode is being used. Make sure it is your local datanode. (You can |
| 76 | + get this from `$ kubectl get pods hadoop -o json | grep hostIP`. Do this |
| 77 | + outside the pod) |
| 78 | + ``` |
| 79 | + $ hadoop --loglevel DEBUG fs \ |
| 80 | + -fs hdfs://hdfs-namenode-0.hdfs-namenode.default.svc.cluster.local \ |
| 81 | + -cat /hosts |
| 82 | + ... |
| 83 | + 17/04/24 20:51:28 DEBUG hdfs.DFSClient: Connecting to datanode 10.128.0.4:50010 |
| 84 | + ... |
| 85 | + ``` |
| 86 | + |
| 87 | + If no, you should check if your local datanode is even in the list from the |
| 88 | + debug messsages above. If it is not, then this is because step (3) did not |
| 89 | + finish yet. Wait more. (You can use a smaller cluster for this test if that |
| 90 | + is possible) |
| 91 | + ``` |
| 92 | + 17/04/24 20:51:28 DEBUG hdfs.DFSClient: newInfo = LocatedBlocks{ |
| 93 | + fileLength=199 |
| 94 | + underConstruction=false |
| 95 | + blocks=[LocatedBlock{BP-347555225-10.128.0.2-1493066928989:blk_1073741825_1001; |
| 96 | + getBlockSize()=199; corrupt=false; offset=0; |
| 97 | + locs=[DatanodeInfoWithStorage[10.128.0.4:50010,DS-d2de9d29-6962-4435-a4b4-aadf4ea67e46,DISK], |
| 98 | + DatanodeInfoWithStorage[10.128.0.3:50010,DS-0728ffcf-f400-4919-86bf-af0f9af36685,DISK], |
| 99 | + DatanodeInfoWithStorage[10.128.0.2:50010,DS-3a881114-af08-47de-89cf-37dec051c5c2,DISK]]}] |
| 100 | + lastLocatedBlock=LocatedBlock{BP-347555225-10.128.0.2-1493066928989:blk_1073741825_1001; |
| 101 | + ``` |
| 102 | + 5. Repeat the `hdfs cat` command multiple times. Check if the same datanode |
| 103 | + is being consistently used. |
0 commit comments