Kubernetes

Publishing and running a microservice devprime on kubernetes

To publish a container image to kubernetes you must have a public image in the docker hub or in repositories such as Azure Container Registry (ACR), Amazon Elastic Container Registry, Google Container Registry, Oracle Cloud Infrastructure Container Registry, and others.

We recommend a reading in the Docker documentation that demonstrates how to build a docker image and publish to a repository.

Creating a deployment file “deployment.yml”
The default procedure in kubernetes is to create a deployment file as “deployment.yml” and include the content below by modifying the image configuration. The “env” parameters that represent the environment variables.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
apiVersion : apps/v1
kind: Deployment
metadata:
  name: ms-order
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ms-order
  template:
    metadata:
      labels:
        app: ms-order
    spec:
      containers:
        - name: ms-order
          image: ms-order:latest
          imagePullPolicy: Always
          ports:
          - containerPort: 80
          env:
           - name: devprime_app
             value: "license=Put your license|||debug=false|||debugstate=false|||debugstream=false|||debugweb=false|||showenviromentvariables=false|||tenancy=[enable=false,type=Shared,cache=State2,gateway=https://localhost:5003]"
           - name: devprime_observability
             value: "enable=true|||saveinfile=false|||hidedetails=false|||hidedatetime=false|||showhttperrors=400"
           - name: devprime_web
             value: "url=http://*:80|||enable=true|||enableswagger=true|||postsuccess=201|||postfailure=500|||getsuccess=200|||getfailure=500|||patchsuccess=200|||patchfailure=500|||putsuccess=200|||putfailure=500|||deletesuccess=200|||deletefailure=500"
           - name: devprime_stream1
             value: "alias=Stream1|||enable=true|||default=true|||streamtype=RabbitMQ|||hostname=rabbitmq.default.svc|||user=guest|||password=guest|||port=5672|||exchange=devprime|||exchangetype=direct|||retry=3|||fallback=State1"
           - name: devprime_state1
             value: "alias=State1|||dbtype=mongodb|||connection=mongodb://mongoadmin:LltF8Nx*yo@mongodb.default.svc:27017|||timeout=5|||retry=2|||dbname=ms-order|||isssl=true|||numberofattempts=4|||durationofbreak=45"
           - name: Devprime_Custom
             value: "stream.orderevents=OrderEvents"
           - name: DevPrime_Security
             value: ""
           - name: DevPrime_Services
             value: "enable=true|||retry=3|||circuitbreak=45|||timeout=10|||connections=[clientid=your client id,clientsecret=your client secret,granttype=client_credentials,name=Services1,tokenuri=your token uri]"        

          resources:
            requests:
             memory: "75Mi"
             cpu: "250m"
            limits:
             memory: "128Mi"
             cpu: "500m"

After creating the file just run the apply.
kubectl apply -f .\deployment.yml

Then just list the pods
kubectl get pods

NAME                        READY   STATUS    RESTARTS   AGE
ms-order-848cc9c6bf-sxkhr   1/1     Running   0          10m

Creating a service file “service.yml”
We will also create a service to get a public ip for that pod. Create the file
“service.yml”.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
apiVersion: v1
kind: Service
metadata:  
  name: ms-order
spec:
  selector:    
    app: ms-order
  type: LoadBalancer
  ports:  
  - name: http
    port: 80
    targetPort: 80

Run apply to create the service in kubernetes
kubectl apply -f .\service.yml

Then just consult and get the ip address.

NAME         TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
ms-order     LoadBalancer   10.0.146.208   20.85.248.63   80:30549/TCP   35m

Now just open your application at the EXTERNAL-IP ip address.

Exporting settings to Kubernetes
DevPrime provides a command to export the initial settings of the Deployment and Servicces file. When running in the project folder it does all the initial steps.
dp export kubernetes

DevPrime Microservices kubernetes

Considerations
We have demonstrated how simple it is to publish a devprime microservices in kubernetes.

  • Use a DevOps process and services like AKS, GKE, EKS, OKE
  • Use vault services for credentials.
Last modified March 10, 2022 (615ec2b)