Thursday, April 27, 2023

Github Actions to Deploy Microservices to Kubernetes on AWS EKS and Oracle Cloud Infrastructure

 Github Actions to Deploy Microservices to Kubernetes

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. You can create workflows that build and test every pull request to your repository, or deploy merged pull requests to production.

GitHub Actions goes beyond just DevOps and lets you run workflows when other events happen in your repository. For example, you can run a workflow to automatically add the appropriate labels whenever someone creates a new issue in your repository.

Code snippet

name: Deploy Spring Boot to Kubernetes

 

on:

  push:

    branches:

      - master

 

jobs:

  build:

    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v2

      - name: Set up Java

        uses: actions/setup-java@v1

        with:

          java-version: 11

      - name: Build with Maven

        run: mvn clean install

 

  deploy:

    needs: build

    runs-on: ubuntu-latest

    steps:

      - uses: actions/checkout@v2

      - name: Set up Kubernetes

        uses: actions/setup-kubernetes@v1

        with:

          kubeconfig: ${{ secrets.KUBECONFIG }}

      - name: Deploy to Kubernetes

        run: kubectl apply -f deployment.yaml

 

This pipeline will first checkout the code from the repository, then set up Java and build the application with Maven. Once the application is built, it will deploy it to Kubernetes using the kubectl apply command.

Here is a breakdown of each step in the pipeline:

  • on: push: branches: master - This event listener will trigger the pipeline when a new commit is pushed to the master branch.
  • jobs: build - This job will build the Spring Boot application.
  • steps: - These steps are executed in order to build the application.
    • uses: actions/checkout@v2 - This step checks out the code from the repository.
    • name: Set up Java - This step sets up Java on the runner.
    • run: mvn clean install - This step builds the application with Maven.
  • jobs: deploy - This job will deploy the Spring Boot application to Kubernetes.
  • needs: build - This job depends on the build job. This means that the deploy job will not start until the build job has completed successfully.
  • steps: - These steps are executed in order to deploy the application to Kubernetes.
    • uses: actions/checkout@v2 - This step checks out the code from the repository.
    • name: Set up Kubernetes - This step sets up Kubernetes on the runner.
    • with: kubeconfig: ${{ secrets.KUBECONFIG }} - This step sets the Kubernetes configuration file as a secret.
    • name: Deploy to Kubernetes - This step deploys the application to Kubernetes using the kubectl apply command.

Deploy Microservice in Oracle Cloud Infrastructure

 

Deploy Microservice in Oracle Cloud Infrastructure

1.   Create a Compute Instance

First, you need to create a Compute Instance in Oracle Cloud Infrastructure. This is a virtual machine that will host your Spring Boot application.

To create a Compute Instance, follow these steps:

1.   Go to the Compute Instances page in the Oracle Cloud Infrastructure Console.

2.   Click Create Instance.

3.   In the Create Instance dialog, select the Operating System and Image for your Compute Instance.

4.   Click Create.

It will take a few minutes for your Compute Instance to be created.

2.   Install Java and Maven

Once your Compute Instance is created, you need to install Java and Maven. Java is the programming language that Spring Boot is written in, and Maven is a build tool that is used to build and deploy Spring Boot applications.

To install Java and Maven, follow these steps:

1.   SSH into your Compute Instance.

2.   Run the following command to install Java:

Code snippet

sudo apt-get install openjdk-11-jdk

 

3.   Run the following command to install Maven:

Code snippet

sudo apt-get install maven

 

3.   Create a Spring Boot Application

Now that you have Java and Maven installed, you can create a Spring Boot application.

To create a Spring Boot application, follow these steps:

1.   Create a new directory for your Spring Boot application.

2.   In the directory, run the following command to create a new Spring Boot project:

mvn archetype:generate -DgroupId=com.example -DartifactId=my-spring-boot-application -DarchetypeArtifactId=maven-archetype-quickstart

This will create a new Spring Boot project with the name my-spring-boot-application.

4.   Build and Deploy the Application

Once you have created a Spring Boot application, you can build and deploy it.

To build and deploy the application, follow these steps:

1.   In the directory of your Spring Boot application, run the following command to build the application:

mvn clean install

 



2.   Run the following command to deploy the application to Oracle Cloud Infrastructure:

cf push my-spring-boot-application

 

 

This will deploy your Spring Boot application to Oracle Cloud Infrastructure.

5.   Access the Application

Once your Spring Boot application is deployed, you can access it by going to the following URL:

https://my-spring-boot-application.[region].oci.oraclecloud.com

 

 

For example, if your application is deployed in the us-central1 region, the URL would be:

https://my-spring-boot-application.us-central1.oci.oraclecloud.com

 

 

You can now access your Spring Boot application in the Oracle Cloud Infrastructure Console.

 

Friday, April 21, 2023

Title: How to Deploy Kubernetes with Helm Charts

 

Title: How to Deploy Kubernetes with Helm Charts

Introduction:

Kubernetes is a powerful container orchestration platform that can be used to deploy

and manage containerized applications. Helm is a package manager for Kubernetes

that makes it easy to deploy and manage Helm charts, which are packages that contain

all the Kubernetes resources needed to deploy an application.

In this blog post, we will show you how to deploy Kubernetes with Helm charts.

We will start by creating a Helm chart for a simple application, and then we will deploy

the application to Kubernetes.

Prerequisites:

· Kubernetes cluster

· Helm

Creating a Helm Chart:

To create a Helm chart, we will use the following command:

helm create my-app

This will create a new directory called my-app that contains the Helm chart for

our application.

The my-app directory contains the following files:

· Chart.yaml: This file contains metadata about the Helm chart, 

· such as the name, version, and description.

· values.yaml: This file contains default values for the Helm chart's parameters.

· templates: This directory contains the Kubernetes resources that will be

· deployed when the Helm chart is installed.

 

Deploying the Helm Chart:

To deploy the Helm chart, we will use the following command:

helm install my-app

This will deploy the Helm chart to Kubernetes.

Once the Helm chart has been deployed, you can verify that the application

is running by using the following command:

kubectl get pods

This command will list all the pods that are running in your Kubernetes cluster.

Conclusion:

In this blog post, we showed you how to deploy Kubernetes with Helm charts.

We started by creating a Helm chart for a simple application, and then

we deployed the application to Kubernetes.

OCI Knowledge Series: OCI Infrastructure components

  Oracle Cloud Infrastructure (OCI) provides a comprehensive set of infrastructure services that enable you to build and run a wide range of...