Install on Kubernetes
Follow the instructions below to deploy WSO2 API Microgateway in Kubernetes.
Step 1 - Follow the installation prerequisites
Make sure to do the following:
Carry out the installation prerequisites for WSO2 API Microgateway Toolkit.
Install and setup kubectl in your client machine.
Setup a Kubernetes cluster.
Make sure that kubectl points to your Kubernetes cluster.
Step 2 - Create a Microgateway project
Navigate to a preferred workspace folder using the command line to set the location that is used to store the Microgateway project.
Create a project.
Let's create a project namedk8s_projectby running the following command. This will create the folder structure for the artifacts to be included.Format
micro-gw init <project_name>Example
micro-gw init k8s_project Project 'k8s_project' is initialized successfully.
Step 3 - Build the Microgateway project
Add the API to the project.
Navigate to the
/petstore/api_definitionsdirectory and add the OpenAPI definition(s) to this directory. Let's use the Petstore sample OpenAPI definition in this scenario.Create the input for WSO2 API Microgateway Toolkit.
Create adeployment.tomlfile that you will use as the input when creating the microgateway project. This TOML file should contain the relevant deployment configurations as shown below. For more information on each of the above parameters, see deployment.toml for Kubernetes.[kubernetes] [kubernetes.kubernetesDeployment] enable = true name = 'k8s' tag = 'v1' #labels = '' replicas = '1' #enableLiveness = '' #initialDelaySeconds = '' #periodSeconds = '' #livenessPort = '' #imagePullPolicy = 'Always' #imagePullSecrets = ['secret1'] #image = '' #env = '' buildImage = true #cmd = 'CMD gateway ${APP} --b7a.config.file=conf/micro-gw.conf --b7a.log.level=DEBUG' #copyFiles = '' #dockerHost = '' #dockerCertPath = '' #push = 'false' #registry = 'index.docker.io/<DOCKER_USERNAME>' #username = '' #password = '' baseImage = 'wso2/wso2micro-gw:3.1.0' [kubernetes.kubernetesDeployment.livenessProbe] enable = true initialDelaySeconds = '20' periodSeconds = '20' [kubernetes.kubernetesDeployment.readinessProbe] enable = true initialDelaySeconds = '30' periodSeconds = '30' [kubernetes.kubernetesServiceHttps] enable = true name = 'httpsService' #labels = '{"": ""}' serviceType = 'NodePort' #port = '' [kubernetes.kubernetesServiceHttp] enable = true name = 'httpService' #labels = '{"": ""}' serviceType = 'NodePort' #port = '' [kubernetes.kubernetesConfigMap] enable = true ballerinaConf = '<MICROGW_TOOLKIT_HOME>/resources/conf/micro-gw.conf'Build the microgateway project.
Use your command line tool to navigate to where the project directory (
k8s_project) was created and execute the following command to build the project.Format
micro-gw build <project_name> --deployment-config deployment.tomlExample
micro-gw build k8s_project --deployment-config deployment.tomlThis generates the following Kubernetes resources.
├── k8s_project│ └── api_definitions│ └── conf│ └── extensions│ └── grpc_definitions│ └── policies.yaml│ └── target│ │ └── gen│ │ │ └── gRPCSrc│ │ │ └── src│ │ │ └── target│ │ │ │ └── balo│ │ │ │ └── bin│ │ │ │ └── caches│ │ │ │ └── docker│ │ │ │ │ └── k8s_project│ │ │ │ │ │ └── Dockerfile│ │ │ │ └── kubernetes│ │ │ │ │ └── k8s_project│ │ │ │ │ │ └── k8s│ │ │ │ │ │ │ └── Chart.yaml│ │ │ │ │ │ │ └── templates│ │ │ │ │ │ │ │ └── k8s_project.yaml│ │ │ │ │ │ └── k8s_project.yaml│ └── k8s_project.jarThe Docker image to be deployed in Kubernetes is created in your local registry. You can find the image
k8s_project:latestwhen you execute the Docker images command.Step 4 - Deploy the Docker image in a Kubernetes environment
Let's SCP the image to the Kubernetes nodes to deploy the Docker image in a K8s environment.
Save the Docker image to a
tarfile.Format
docker save <MGW-project-name>:latest > <Docker-image-name>.tarExample
docker save k8s_project:latest > image.tarSCP the image to the Kubernetes nodes.
Format
scp -i <identity-file> image.tar username@<K8s_NODE_IP>:Identity file- This refers to the public key of the Kubernetes node. For example you can get a google_compute_engine.pub for GCE. You have toscpthe Docker image for each and every Kubernetes node.
Load the Docker image in the Kubernetes nodes.
You need to execute the following command in the Kubernetes nodes.Format
docker load < [Docker-image-name].tarExample
docker load < image.tar