LIGHT

  • News
  • Docs
  • Community
  • Reddit
  • GitHub
Star

Deploy to Kubernetes

Although you can deploy the microservices built on top of Light to a data center with java -jar or with Docker, the ultimate deployment platform would be a Kubernetes cluster.

Before deploying a service to a Kubernetes cluster, you need to create secrets with all the externalized configuration files. These files usually are copied to the config folder in each project in llight-config-test or light-config-prod. For a detailed directory structure, please refer to petstore.

Secrets

To create secrets, make sure you have all the configuration files in the config folder. Then run the following create_secrets.sh:

kubectl create secret generic petstore-secret --from-file=config

The above script creates a generic secret object with all the config files in the config folder. Each file name will be the key and the base64 encoded content will be the value.

To list all the secrets:

kubectl get secrets

To view the content of a specific secret:

kubectl get secret petstore-secret -o yaml

To delete a secret:

kubectl delete secret petstore-secret

Deployment

To deploy the service to a Kubernetes cluster, we need to create a deployment.yaml file with the following content:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: swagger-petstore-deployment
  labels:
    app: swagger-petstore
spec:
  replicas: 1
  selector:
    matchLabels:
      app: swagger-petstore
  template:
    metadata:
      labels:
        app: swagger-petstore
    spec:
      hostNetwork: true
      containers:
      - name: swagger-petstore
        image: networknt/com.networknt.petstore-2.0.0
        resources:
          limits:
            memory: 512Mi
          requests:
            memory: 256Mi
        env:
        - name: STATUS_HOST_IP
          valueFrom:
            fieldRef:
              fieldPath: status.hostIP
        volumeMounts:
        - name: config
          mountPath: "/config"
          readOnly: true
      volumes:
      - name: config
        secret:
          secretName: petstore-secret

Note that hostNetwork is used so that the service can register itself to Consul during startup. Also, status.hostIP is passed to the container to get the host IP address. The previously created secret is used in the volumes and volumeMounts.

To start the service:

kubectl create -f deployment.yaml

To delete the service:

kubectl delete -f deployment.yaml

To list all the running pods:

kubectl get pods

Memory Limit

In the above deployment.yaml, we have set the memory limit for the container. To verify that, let’s put some load on the server and see if the service respects the limitation.

To access the server, go to the consul server first to find the IP and port number for the petstore service. Verify if it works with a curl command:

curl -k https://38.113.162.51:2408/v2/pet/111

Now use the wrk to generate some load for 5 minutes:

wrk -t1 -c128 -d300s https://38.113.162.51:2408/v2/pet/111

To monitor the memory usage, login to the node which petstore is deployed and find the container id with:

docker ps

With the id found above, issue the following command to monitor the container memory usage:

docker stats {containerid}

You will find that the container only uses about 300MB memory with the limit of 512MB.

  • About Light
    • Overview
    • Testimonials
    • What is Light
    • Features
    • Principles
    • Benefits
    • Roadmap
    • Community
    • Articles
    • Videos
    • License
    • Why Light Platform
  • Getting Started
    • Get Started Overview
    • Environment
    • Light Codegen Tool
    • Light Rest 4j
    • Light Tram 4j
    • Light Graphql 4j
    • Light Hybrid 4j
    • Light Eventuate 4j
    • Light Oauth2
    • Light Portal Service
    • Light Proxy Server
    • Light Router Server
    • Light Config Server
    • Light Saga 4j
    • Light Session 4j
    • Webserver
    • Websocket
    • Spring Boot Servlet
  • Architecture
    • Architecture Overview
    • API Category
    • API Gateway
    • Architecture Patterns
    • CQRS
    • Eco System
    • Event Sourcing
    • Fail Fast vs Fail Slow
    • Integration Patterns
    • JavaEE declining
    • Key Distribution
    • Microservices Architecture
    • Microservices Monitoring
    • Microservices Security
    • Microservices Traceability
    • Modular Monolith
    • Platform Ecosystem
    • Plugin Architecture
    • Scalability and Performance
    • Serverless
    • Service Collaboration
    • Service Mesh
    • SOA
    • Spring is bloated
    • Stages of API Adoption
    • Transaction Management
    • Microservices Cross-cutting Concerns Options
    • Service Mesh Plus
    • Service Discovery
  • Design
    • Design Overview
    • Design First vs Code First
    • Desgin Pattern
    • Service Evolution
    • Consumer Contract and Consumer Driven Contract
    • Handling Partial Failure
    • Idempotency
    • Server Life Cycle
    • Environment Segregation
    • Database
    • Decomposition Patterns
    • Http2
    • Test Driven
    • Multi-Tenancy
    • Why check token expiration
    • WebServices to Microservices
  • Cross-Cutting Concerns
    • Concerns Overview
  • API Styles
    • Light-4j for absolute performance
    • Style Overview
    • Distributed session on IMDG
    • Hybrid Serverless Modularized Monolithic
    • Kafka - Event Sourcing and CQRS
    • REST - Representational state transfer
    • Web Server with Light
    • Websocket with Light
    • Spring Boot Integration
    • Single Page Application
    • GraphQL - A query language for your API
    • Light IBM MQ
    • Light AWS Lambda
    • Chaos Monkey
  • Infrastructure Services
    • Service Overview
    • Light Proxy
    • Light Mesh
    • Light Router
    • Light Portal
    • Messaging Infrastructure
    • Centralized Logging
    • COVID-19
    • Light OAuth2
    • Metrics and Alerts
    • Config Server
    • Tokenization
    • Light Controller
  • Tool Chain
    • Tool Chain Overview
  • Utility Library
  • Service Consumer
    • Service Consumer
  • Development
    • Development Overview
  • Deployment
    • Deployment Overview
    • Frontend Backend
    • Linux Service
    • Windows Service
    • Install Eventuate on Windows
    • Secure API
    • Client vs light-router
    • Memory Limit
    • Deploy to Kubernetes
  • Benchmark
    • Benchmark Overview
  • Tutorial
    • Tutorial Overview
  • Troubleshooting
    • Troubleshoot
  • FAQ
    • FAQ Overview
  • Milestones
  • Contribute
    • Contribute to Light
    • Development
    • Documentation
    • Example
    • Tutorial
“Deploy to Kubernetes” was last updated: April 5, 2021: Issue246 (#256) (50b1c10)
Improve this page
  • News
  • Docs
  • Community
  • Reddit
  • GitHub
  • About Light
  • Getting Started
  • Architecture
  • Design
  • Cross-Cutting Concerns
  • API Styles
  • Infrastructure Services
  • Tool Chain
  • Utility Library
  • Service Consumer
  • Development
  • Deployment
  • Benchmark
  • Tutorial
  • Troubleshooting
  • FAQ
  • Milestones
  • Contribute