Install and Configure MuleSoft Flex Gateway in Kubernetes Cluster With K3D
This tutorial provides a demonstration of how to install Anypoint Flex Gateway in the Kubernetes cluster with k3d.
Join the DZone community and get the full member experience.
Join For FreeIn this tutorial, we will install Anypoint Flex Gateway in the Kubernetes cluster with k3d.
About k3d
k3d provides easy and configurable steps to create a lightweight cluster using Kubernetes with extremely limited/lower resources. Furthermore, it backs and simplifies tasks related to Kubernetes configurations and clusters. It is primarily used to create a Kubernetes cluster with Docker containers which can be extended.
Let's Install It (k3d)
mulesoft@mulesoft-VirtualBox:~$ sudo curl -s https://raw.githubusercontent.com/rancher/k3d/main/install.sh | bash
Preparing to install k3d into /usr/local/bin
k3d installed into /usr/local/bin/k3d
Run 'k3d --help' to see what you can do with it.
mulesoft@mulesoft-VirtualBox:~$
Validate k3d Installation
mulesoft@mulesoft-VirtualBox:~$ k3d --help
https://k3d.io/
k3d is a wrapper CLI that helps you to easily create k3s clusters inside docker.
Nodes of a k3d cluster are docker containers running a k3s image.
All Nodes of a k3d cluster are part of the same docker network.
Usage:
k3d [flags]
k3d [command]
Available Commands:
cluster Manage cluster(s)
completion Generate completion scripts for [bash, zsh, fish, powershell | psh]
config Work with config file(s)
k3d is installed and ready to use.
About Kubernetes
Kubernetes is an unrestricted origin container orchestration engine for self-managed deployment, scaling, and managing containerized apps. We call it "k8s" and "Kube." It is open-source and supports a container-based platform. It automates numerous of the manual configuration and efforts needed for deploying and controlling containerized applications.
Let's Install It (Kubernetes)
We are using a server configured with "Ubuntu 20.04.4 LTS;" hence, we will follow Linux-based Kubernetes steps with root or sudo user.
- Download the latest release of Kubernetes with the
curl
command.
mulesoft@mulesoft-VirtualBox:~$ sudo curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 154 100 154 0 0 447 0 --:--:-- --:--:-- --:--:-- 447
100 43.5M 100 43.5M 0 0 5002k 0 0:00:08 0:00:08 --:--:-- 5342k
mulesoft@mulesoft-VirtualBox:~$
- Download the kubectl checksum file.
mulesoft@mulesoft-VirtualBox:~$ sudo curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 154 100 154 0 0 436 0 --:--:-- --:--:-- --:--:-- 436
100 64 100 64 0 0 84 0 --:--:-- --:--:-- --:--:-- 323
mulesoft@mulesoft-VirtualBox:~$
- Validate installable download:
mulesoft@mulesoft-VirtualBox:~$ echo "$(cat kubectl.sha256) kubectl" | sha256sum --check
kubectl: OK
mulesoft@mulesoft-VirtualBox:~$
- Install kubectl now:
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
- Validate kubectl installation:
mulesoft@mulesoft-VirtualBox:/usr/local/bin$ ls
k3d kubectl
mulesoft@mulesoft-VirtualBox:/usr/local/bin$ kubectl version --client
WARNING: This version information is deprecated and will be replaced with the output from kubect l version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.1", GitCommit:"3ddd0f45aa9 1e2f30c70734b175631bec5b5825a", GitTreeState:"clean", BuildDate:"2022-05-24T12:26:19Z", GoVersio n:"go1.18.2", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.4
mulesoft@mulesoft-VirtualBox:/usr/local/bin$
mulesoft@mulesoft-VirtualBox:/usr/local/bin$
mulesoft@mulesoft-VirtualBox:/usr/local/bin$ kubectl version --client --output=yaml
clientVersion:
buildDate: "2022-05-24T12:26:19Z"
compiler: gc
gitCommit: 3ddd0f45aa91e2f30c70734b175631bec5b5825a
gitTreeState: clean
gitVersion: v1.24.1
goVersion: go1.18.2
major: "1"
minor: "24"
platform: linux/amd64
kustomizeVersion: v4.5.4
mulesoft@mulesoft-VirtualBox:
mulesoft@mulesoft-VirtualBox:~$ sudo kubectl version --client
[sudo] password for mulesoft:
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short. Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"24", GitVersion:"v1.24.1", GitCommit:"3ddd0f45aa91e2f30c70734b175631bec5b5825a", GitTreeState:"clean", BuildDate:"2022-05-24T12:26:19Z", GoVersion:"go1.18.2", Compiler:"gc", Platform:"linux/amd64"}
Kustomize Version: v4.5.4
mulesoft@mulesoft-VirtualBox:~$
Kubernetes is ready to use now!
About Helm
Helm is a Kubernetes deployment tool for self-managing the packaging, configuration, and deployment of apps and assistance to Kubernetes clusters. It facilitates Kubernetes to deal with multiple resources with a dedicated YAML manifest file. To find out more, refer to the Helm docs.
Let's Install It (Helm)
- As we are using Ubuntu, we will follow specific steps to install it on the Ubuntu server. Execute the below steps to add to the repository.
mulesoft@mulesoft-VirtualBox:/usr/local/bin$ sudo curl https://baltocdn.com/helm/signing.asc | gpg --dearmor | sudo tee /usr/share/keyrings/helm.gpg > /dev/null
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1700 100 1700 0 0 7172 0 --:--:-- --:--:-- --:--:-- 7172
mulesoft@mulesoft-VirtualBox:
mulesoft@mulesoft-VirtualBox:/usr/local/bin$ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
deb [arch=amd64 signed-by=/usr/share/keyrings/helm.gpg] https://baltocdn.com/helm/stable/debian/ all main
mulesoft@mulesoft-VirtualBox:/usr/local/bin$ sudo apt-get update
Get:1 https://baltocdn.com/helm/stable/debian all InRelease [7,652 B]
Hit:2 http://ca.archive.ubuntu.com/ubuntu focal InRelease
Hit:3 http://ca.archive.ubuntu.com/ubuntu focal-updates InRelease
Get:5 https://baltocdn.com/helm/stable/debian all/main amd64 Packages [2,684 B]
Hit:6 http://ca.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:7 http://security.ubuntu.com/ubuntu focal-security InRelease
Get:4 https://packages.cloud.google.com/apt kubernetes-xenial InRelease [9,383 B]
Fetched 19.7 kB in 1s (17.1 kB/s)
Reading package lists... Done
- Now, install Helm:
mulesoft@mulesoft-VirtualBox:/usr/local/bin$ sudo apt-get install helm
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
helm
0 upgraded, 1 newly installed, 0 to remove and 184 not upgraded.
Need to get 13.9 MB of archives.
After this operation, 46.2 MB of additional disk space will be used.
Get:1 https://baltocdn.com/helm/stable/debian all/main amd64 helm amd64 3.9.0-1 [13.9 MB]
Fetched 13.9 MB in 3s (5,054 kB/s)
Selecting previously unselected package helm.
(Reading database ... 180631 files and directories currently installed.)
Preparing to unpack .../helm_3.9.0-1_amd64.deb ...
Unpacking helm (3.9.0-1) ...
Setting up helm (3.9.0-1) ...
Processing triggers for man-db (2.9.1-1) ...
One last component that needs to be installed is Docker. To do this, follow the steps below.
Docker Installation
Allow Anypoint to access the repository with HTTPS:
mulesoft@mulesoft-VirtualBox:~$ sudo apt-get install ca-certificates curl gnupg lsb-release
Reading package lists... Done
Building dependency tree
Reading state information... Done
lsb-release is already the newest version (11.1.0ubuntu2).
lsb-release set to manually installed.
Docker’s official GPG key:
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Set up the repository:
Now, our server is ready to install the Anypoint Flex Gateway.
Install Flex Gateway
- Create a cluster and download the
flex-gateway
image. The command will be provided on the Anypoint platform control plane page. In this command, there is no node assigned, and the controller will be defined by default 1. We will assign the node later in the steps.
sudo k3d cluster create flex-gateway-1 --k3s-arg "--disable=traefik@server:*" --port '80:80@server:*' --port '443:443@server:*'
- Check the cluster status which we created in the previous step.
mulesoft@mulesoft-VirtualBox:~$ sudo kubectl cluster-info
Kubernetes control plane is running at https://0.0.0.0:33877
CoreDNS is running at https://0.0.0.0:33877/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://0.0.0.0:33877/api/v1/namespaces/kube-system/services/https:metrics-server:https/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
mulesoft@mulesoft-VirtualBox:~$
- Register cluster to Anypoint platform.
mulesoft@mulesoft-VirtualBox:~$ sudo docker run --entrypoint flexctl -w /registration -v "$(pwd)":/registration mulesoft/flex-gateway:1.0.0 register kube-flexgateway --token=5d80d981-81d7-4e2e-8422-e3072eaXXXX --organization=464fcf12-56f8-4197-9f27-2fc9a8XXXX --connected=true
Unable to find image 'mulesoft/flex-gateway:1.0.0' locally
1.0.0: Pulling from mulesoft/flex-gateway
ddbb808fb52e: Pull complete
Digest: sha256:b408f563da559d352d32b0ca24d02835d5a8fb18ef6a4b6a1594af6ebe66c82f
Status: Downloaded newer image for mulesoft/flex-gateway:1.0.0
Starting registration, please be patient.
Registration completed, the configuration files were written in directory ".".
- Install:
- Create a Kubernetes secret:
mulesoft@mulesoft-VirtualBox:~$ sudo kubectl -n gateway create secret generic 6d8286df-c63c-4945-b77d-603312eXXXXX --from-file=platform.conf=6d8286df-c63c-4945-b77d-603312eXXXXX.conf --from-file=platform.key=6d8286df-c63c-4945-b77d-603312eXXXXX.key --from-file=platform.pem=6d8286df-c63c-4945-b77d-603312eXXXXX.pem
secret/6d8286df-c63c-4945-b77d-603312eXXXXX created
mulesoft@mulesoft-VirtualBox:~$
mulesoft@mulesoft-VirtualBox:~$ sudo helm repo add flex-gateway https://flex-packages.anypoint.mulesoft.com/helm
"flex-gateway" has been added to your repositories
mulesoft@mulesoft-VirtualBox:~$
mulesoft@mulesoft-VirtualBox:~$ sudo helm -n gateway upgrade -i --wait ingress flex-gateway/flex-gateway --set registerSecretName=6d8286df-c63c-4945-b77d-603312eXXXXX
Release "ingress" does not exist. Installing it now.
NAME: ingress
LAST DEPLOYED: Sat Jun 4 13:30:30 2022
NAMESPACE: gateway
STATUS: deployed
REVISION: 1
TEST SUITE: None
- Add the node in the k3d cluster:
mulesoft@mulesoft-VirtualBox:~$ sudo k3d node create node-one --role agent --cluster flex-gateway-1
INFO[0000] Adding 1 node(s) to the runtime local cluster 'flex-gateway-1'...
INFO[0000] Using the k3d-tools node to gather environment information
INFO[0000] Starting new tools node...
INFO[0000] Starting Node 'k3d-flex-gateway-1-tools'
INFO[0000] HostIP: using network gateway 172.18.0.1 address
INFO[0001] Starting Node 'k3d-node-one-0'
INFO[0009] Successfully created 1 node(s)!
mulesoft@mulesoft-VirtualBox:~$
mulesoft@mulesoft-VirtualBox:~$ sudo k3d node create node-two --role agent --cluster flex-gateway-1
INFO[0000] Adding 1 node(s) to the runtime local cluster 'flex-gateway-1'...
INFO[0000] Using the k3d-tools node to gather environment information
INFO[0000] Starting new tools node...
INFO[0000] Starting Node 'k3d-flex-gateway-1-tools'
INFO[0001] HostIP: using network gateway 172.18.0.1 address
INFO[0001] Starting Node 'k3d-node-two-0'
INFO[0009] Successfully created 1 node(s)!
mulesoft@mulesoft-VirtualBox:~$
- Now, check the cluster list:
mulesoft@mulesoft-VirtualBox:~$ sudo k3d cluster list
NAME SERVERS AGENTS LOADBALANCER
flex-gateway-1 1/1 2/2 true
mulesoft@mulesoft-VirtualBox:~$
Anypoint flex-gateway is registered and active in the control plane.
Note: While creating the cluster, we have enabled port 80; hence, only the same will be configurable for the application proxy. It will not support any other port for API.
The API resource is configured using the Anypoint control plane with port 80 and flex-gateway (Kubernetes cluster) as below.
It's working! My temp server IP is 172.20.10.8.
This is an easy and configurable approach to managing the Anypoint platform Flex Gateway on the server.
Opinions expressed by DZone contributors are their own.
Comments