Ballerina and Kubernetes Microservice in Practice with · Microservice in Practice with Ballerina...

Post on 16-Jul-2020

10 views 0 download

Transcript of Ballerina and Kubernetes Microservice in Practice with · Microservice in Practice with Ballerina...

Lakmal Warusawithana | @lakwarus

Microservice in Practice with Ballerina and Kubernetes

Everything is An Endpoint

Functions

APIs

Data

SaaS apps

Legacy apps

Devices

TransactionsCircuit Breaking

ProtocolsPayloads

EventsSecurity

WorkflowStreams

Compensation

+

Optimized for Writing Network Distributed Applications

Let’s write a Microservice

● Ballerina supports high level network abstractions.

● Ballerina natively understands data types like JSON and XML.

● Ballerina has self documentation which can generate sequence diagram out of your code.

● Ballerina protects sensitive data by default.

Let’s deploy the Microservice

FROM ballerina/ballerina

COPY hello.balx /home/ballerina

EXPOSE 9090

CMD ballerina run hello.balx

$> docker build -t hello .

Sending build context to Docker daemon 7.168kB

Step 1/4 : from ballerina/ballerina

---> a65975411327

Step 2/4 : COPY hello.balx /home/ballerina

---> 3b4e481bef57

Step 3/4 : EXPOSE 9090

---> d95a1292b232

Step 4/4 : CMD ballerina run hello.balx

---> 2698c40bdadd

Successfully built 2698c40bdadd

Successfully tagged hello:latest

$> docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

hello latest 2698c40bdadd 1 minute ago 128MB

apiVersion: apps/v1kind: Deploymentmetadata: name: hello-deployment labels: app: hellospec: replicas: 1 selector: matchLabels: app: hello template: metadata: labels: app: hello spec: containers: - name: hello image: hello:latest imagePullPolicy: "IfNotPresent" ports: - containerPort: 9090

$>kubectl apply -f deployment.yaml

deployment.extensions "hello-deployment" created

$>kubectl get pods

NAME READY STATUS RESTARTS AGE

hello-666f4f4bbf 1/1 Running 0 50s

apiVersion: "v1"kind: "Service"metadata: labels: app: "hello" name: "hello"spec: ports: - port: 9090 protocol: "TCP" targetPort: 9090 selector: app: "hello" type: "NodePort"

$>kubectl apply -f hello-service.yaml

service "hello-service" created

$>kubectl get service

NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE

hello NodePort 10.110.136.115 <none> 9090:31657/TCP 5m

$>kubectl create configmap hello \

--from-env-file=twitter.toml

configmap "hello" created

Update Deployment yaml with config-map

volumeMounts:

- mountPath: "/home/ballerina/conf/"

name: "hello"

Ballerina K8S Demo

A service mesh is a dedicated infrastructure layer that controls service-to-service communication over a network. It provides a method in which separate parts of an application can communicate with each other.

source:techtarget.com

Ballerina Istio Demo

● Kubernetes (K8s) is an open-source system for automating deployment, scaling, and management of containerized applications.

● Ballerina natively understand Cloud Native platforms like Docker, Kubernetes and Istio.

● Ballerina and Kubernetes support agile development to deployment and improve productivity.

Learn more

Open source

Get support

http://ballerina.io

http://github.com/ballerina-platform/

Stack Overflow #ballerina tag

THANK YOU