github.com/cilium/cilium@v1.16.2/Documentation/network/external-workloads.rst (about) 1 .. only:: not (epub or latex or html) 2 3 WARNING: You are looking at unreleased Cilium documentation. 4 Please use the official rendered version released here: 5 https://docs.cilium.io 6 7 .. _external_workloads: 8 9 .. _gs_external_workloads: 10 11 ************************************************* 12 Setting up Support for External Workloads (beta) 13 ************************************************* 14 15 This is a step-by-step guide on how to add external workloads (such as 16 VMs) in to your Kubernetes cluster and to enforce security policies to 17 restrict access. 18 19 .. include:: ../beta.rst 20 21 Prerequisites 22 ############# 23 24 * Cilium must be configured to use Kubernetes for identity allocation 25 (``identityAllocationMode`` set to ``crd``). This is the default 26 for new installations. 27 28 * External workloads must run a recent enough kernel (>= 4.19.57) for k8s 29 service access from the external host to work, see 30 :ref:`kubeproxy-free` for details. 31 32 * External workloads must have Docker 20.10 or newer installed on the 33 system (a version which supports ``--cgroupns`` CLI option). 34 35 * External workloads must have IP connectivity with the nodes in your 36 cluster. This requirement is typically met by running your VMs in 37 the same cloud provider virtual network (e.g., GCP VPC) as your k8s 38 cluster, or establishing peering or VPN tunnels between the networks 39 of the nodes of your cluster and your external workloads. Note that 40 this precludes any VMs running behind NATs. 41 42 * All external workloads must have a unique IP address assigned 43 them. Node IPs of such nodes and your clusters must not conflict with 44 each other. 45 46 * The network between the external workloads and your cluster must 47 allow the node-cluster communication. The exact ports are documented 48 in the :ref:`firewall_requirements` section. 49 50 * This guide assumes your external workload manages domain name 51 resolution service by a stand-alone ``/etc/resolv.conf``, or via 52 systemd (e.g., Ubuntu). 53 54 * So far this functionality is only tested with the vxlan tunneling 55 datapath mode (default for most installations). 56 57 Limitations 58 ########### 59 60 * Transparent encryption of traffic to/from external workloads is currently not 61 supported. 62 63 Prepare your cluster 64 #################### 65 66 Enable support for external workloads 67 ===================================== 68 69 Your cluster must be configured with support for external workloads 70 enabled. This can be done with the cilium CLI tool by issuing ``cilium 71 clustermesh enable`` after ``cilium install``: 72 73 .. parsed-literal:: 74 75 cilium install |CHART_VERSION| --set routingMode=tunnel 76 cilium clustermesh enable --service-type LoadBalancer --enable-external-workloads 77 78 The ``routingMode=tunnel`` Helm value configures Cilium in tunneling mode. 79 This is currently a requirement for external workload support. 80 81 This will add a deployment for ``clustermesh-apiserver`` into your 82 cluster, as well as the related cluster resources, such as TLS 83 secrets. ``clustermesh-apiserver`` service is exposed to the external 84 workloads. If your are on GKE, EKS, or AKS, this is done by default 85 using the internal ``LoadBalancer`` service type. Override the 86 auto-detection with an explicit ``--service-type LoadBalancer`` to use 87 an external LoadBalancer service type that uses an IP that is 88 accessible from outside of the cluster. 89 90 .. note:: 91 92 Use the ``--help`` option after any of the ``cilium clustermesh`` 93 commands to see a short synopsis of available command options. 94 95 Tell your cluster about external workloads 96 ========================================== 97 98 To allow an external workload to join your cluster, the cluster must 99 be informed about each such workload. This is done by creating a 100 ``CiliumExternalWorkload`` (CEW) resource for each external 101 workload. CEW resource specifies the name and identity labels 102 (including namespace) for the workload. The name must be the hostname 103 of the external workload, as returned by the ``hostname`` command run 104 in the external workload. In this example this is ``runtime``. For now 105 you must also allocate a small IP CIDR that must be unique to each 106 workload. For example, for a VM named ``runtime`` that is to join the 107 ``default`` namespace (``vm`` is an alias for the 108 ``external-workload`` subcommand): 109 110 .. code-block:: shell-session 111 112 cilium clustermesh vm create runtime -n default --ipv4-alloc-cidr 10.192.1.0/30 113 114 ``-n`` is an alias for ``--namespace`` and can be left out when the 115 value is ``default``. The namespace value will be set as an identity 116 label. The CEW resource itself is not namespaced. 117 118 To see the list of existing CEW resources, run: 119 120 .. code-block:: shell-session 121 122 cilium clustermesh vm status 123 124 Note that CEW resources are not namespaced, so this command shows the 125 status of all CEW resources regardless of the namespace label that was 126 used when creating them. ``--namespace`` option for the status command 127 controls the namespace of Cilium deployment in your cluster and 128 usually needs to be left as the default ``kube-system``. 129 130 At this point the ``IP:`` in the status for ``runtime`` is ``N/A`` to 131 inform that the VM has not yet joined the cluster. 132 133 Install and configure Cilium on external workloads 134 ################################################## 135 136 Run the external workload install command on your k8s cluster. This 137 extracts the TLS certificates and other access information from the 138 cluster installation and writes out an installation script to be used 139 in the external workloads to install Cilium and connect it to your k8s 140 cluster: 141 142 .. code-block:: shell-session 143 144 cilium clustermesh vm install install-external-workload.sh 145 146 Note that the created script embeds the IP address for the 147 ``clustermesh-apiserver`` service. If service type ``LoadBalancer`` 148 can not be used, this IP address will be the one of the first node in 149 your k8s cluster (for ``NodePort`` service type). If this node is 150 removed from the cluster the above step for creating the installation 151 script must be repeated and all the external workloads 152 reinstalled. ``LoadBalancer`` is not affected by a node removal. 153 154 Log in to the external workload. First make sure the hostname matches 155 the name used in the CiliumExternalWorkload resource: 156 157 .. code-block:: shell-session 158 159 hostname 160 161 Next, copy ``install-external-workload.sh`` created above to the 162 external workload. Then run the installation script: 163 164 .. code-block:: shell-session 165 166 ./install-external-workload.sh 167 168 This command launches the Cilium agent in a docker container named 169 ``cilium`` and copies the ``cilium-dbg`` node CLI to your host. This needs 170 ``sudo`` permissions, so you may be asked for a password. Note that 171 this ``cilium-dbg`` command is not the same as the ``cilium`` CLI used to 172 manage Cilium installation on a k8s cluster. 173 174 This command waits until the node has been connected to the cluster 175 and the cluster services are available. Then it re-configures 176 ``/etc/resolv.conf`` with the IP address of the ``kube-dns`` service. 177 178 .. note:: 179 180 If your external workload node has multiple IP addresses you may 181 need to tell Cilium agent which IP to use. To this end add 182 ``HOST_IP=<ip-address>`` to the beginning of the command line 183 above. 184 185 Verify basic connectivity 186 ========================= 187 188 Next you can check the status of the Cilium agent in your external workload: 189 190 .. code-block:: shell-session 191 192 sudo cilium-dbg status 193 194 You should see something like: 195 196 .. code-block:: shell-session 197 198 KVStore: Ok etcd: 1/1 connected, lease-ID=7c02748328e75f57, lock lease-ID=7c02748328e75f59, has-quorum=true: https://clustermesh-apiserver.cilium.io:32379 - 3.4.13 (Leader) 199 Kubernetes: Disabled 200 ... 201 202 Check that cluster DNS works: 203 204 .. code-block:: shell-session 205 206 nslookup -norecurse clustermesh-apiserver.kube-system.svc.cluster.local 207 208 Inspecting status changes in the cluster 209 ======================================== 210 211 The following command in your cluster should show the external workload IPs and their Cilium security IDs: 212 213 .. code-block:: shell-session 214 215 kubectl get cew 216 217 External workloads should also be visible as Cilium Endpoints: 218 219 .. code-block:: shell-session 220 221 kubectl get cep 222 223 Apply Cilium Network Policy to enforce traffic from external workloads 224 ###################################################################### 225 226 From the external workload, ping the backend IP of ``clustermesh-apiserver`` service to verify connectivity: 227 228 .. code-block:: shell-session 229 230 ping $(sudo cilium-dbg service list get -o jsonpath='{[?(@.spec.flags.name=="clustermesh-apiserver")].spec.backend-addresses[0].ip}') 231 232 The ping should keep running also when the following CCNP is applied in your cluster: 233 234 .. code-block:: yaml 235 236 apiVersion: cilium.io/v2 237 kind: CiliumClusterwideNetworkPolicy 238 metadata: 239 name: test-ccnp 240 namespace: kube-system 241 spec: 242 endpointSelector: 243 matchLabels: 244 k8s-app: clustermesh-apiserver 245 ingress: 246 - fromEndpoints: 247 - matchLabels: 248 io.kubernetes.pod.name: runtime 249 - toPorts: 250 - ports: 251 - port: "2379" 252 protocol: TCP 253 254 The ping should stop if you delete these lines from the policy (e.g., ``kubectl edit ccnp test-ccnp``): 255 256 .. code-block:: yaml 257 258 - fromEndpoints: 259 - matchLabels: 260 io.kubernetes.pod.name: runtime 261 262 The ping should continue if you delete the policy: 263 264 .. code-block:: shell-session 265 266 kubectl delete ccnp test-ccnp 267 268 Clean-up 269 ######## 270 271 You can remove the Cilium installation from your external workload by 272 running the installation script with the ``uninstall`` argument: 273 274 .. code-block:: shell-session 275 276 ./install-external-workload.sh uninstall 277 278 279 Conclusion 280 ########## 281 282 With the above we have enabled policy-based communication between 283 external workloads and pods in your Kubernetes cluster. We have also 284 established service load-balancing from external workloads to your 285 cluster backends, and configured domain name lookup in the external 286 workload to be served by kube-dns of your cluster.