Git Config

Git Config commands git config –global init.defaultBranch main

August 8, 2022 1 min

Kotlin Enum

Let’s have a look at enums in kotlin. Unlike Java, where enum is a Type; in Kotlin, enums are classes Defining an enum 1 2 3 enum class Direction { NORTH, SOUTH, WEST, EAST } Defining an enum with a variable 1 2 3 enum class Direction(val shortName: Char) { NORTH('N'), SOUTH('S'), WEST('W'), EAST('E') } Template Method pattern in Enum 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 enum class Direction(val shortName: Char) { NORTH('N') { override fun move() = "Moving in North Direction" }, SOUTH('S') { override fun move() = "Moving in South Direction" }, WEST('W'){ override fun move() = "Moving in West Direction" }, EAST('E'){ override fun move() = "Moving in East Direction" }; abstract fun move(): String } Companion methods in enum 1 2 3 4 5 6 7 enum class Direction(val shortName: String) { NORTH("N"), SOUTH("S"), WEST("W"), EAST("E"); companion object { fun valueOfIgnoreCase(name: String) = valueOf(name....

Bastion Pod in Kubernetes

Background When deploying applications to kubernetes, we should restrict access to resources like databases, queues, cache, etc. From a security prospective, we should not be able to connect to storage/database from outside the kubernetes deployment(applications). Only applications deployed to kubernetes cluster should be allowed access to databases,queues, etc. Problem But for debugging purpose its essential to be able to connect to such resources. For e.g. we might need to check some data in the database or verify if an item is getting stored in redis cache, etc...

Springdoc OpenApi3 Swagger

When working as a backend engineer, it is essential to document the REST APIs. It also helps in providing a UI(swagger-ui) to test the REST calls. Let us try to integrate springdoc-openapi to provide swagger documentation for a spring boot project using spring-security(OAuth2). Add the dependencies to build.gradle 1 2 3 implementation("org.springdoc:springdoc-openapi-ui:1.6.8") implementation("org.springdoc:springdoc-openapi-security:1.6.8") implementation("org.springdoc:springdoc-openapi-kotlin:1.6.8") Kotlin code example The following example showcases spring configuration to create OpenAPI bean which supports two authentication mechanism:...

Ansible introduction

Ansible introduction Modules Command module: Takes the command and executes it Shell module: Executes through a shell like /bin/sh Script module: Runs a local script on a remote node after transferring it. raw: executes a ssh command. useful for installation python3 Adhoc commands Examples: ansible all - ping ansible web -m command -a “uptime” ansible localhost -m setup Static inventory Sample inventory: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 [control] control ansible_host=10....

GitOps

GitOps Three pillars of GitOps Pipelines Observability Control ##Joined Up Pipelines CI CD Release Automation Git as source of truth Service Deployments are controlled using operator pattern in jubernetes Kubernetes pattern - Git config -> Deploy Operator > service/deployments Similarly now in gitops config is code and everything is config code and config must be version controlled kubectl get <object> -o yaml --export to extract existing configuration to bootstrap config repo in git Sometimes export is not perfect....

Kubernetes introduction

Kubernetes Introduction Build a docker image Dockerfile default filename FROM base image to be used for container ADD copies files/directories/remote file urls to container filesystem. Tarball and Remote URL (git, http) handling COPY same as ADD without tar and remote url handling CMD kubectl –namespace <DEV|STAGING|PROD> get deployments,pods,svc,ingress cd scripts/ ./createServicePrincipal.sh tti-maps-k8s-sp Module 1 creating a cluster 1 2 3 4 5 6 minikube start minikube dashboard kubectl version kubectl cluster-info kubectl get nodes,pods kubectl get nodes --help Module 2 deploy an app Create a deployment using kubectl create deployment...

Docker introduction

Docker for Java Developers Basic Docker commands docker images ls to list docker images docker container ls to list containers Containers and Images Docker CLI docker info shows basic docker infor about containers/images/volumes, runtimes, kernal version, OS details, etc docker version client and server version for docker api docker --help list of commands available prefer to use management commands like: docker image ls docker container ls Run a container docker container run jboss/wildfly download wildfly and run it....

Prometheus

Prometheus Type of logs Transaction logs Request logs Application logs Debug logs Using Expression browser Metrics: up Gauges: process_resident_memory - metric type gauges . For a gauge, its current absolute value is important from a monitoring point of view Counters: prometheus_tsdb_head_samples_appended_total metric type - counter. Number of samples prometheus has ingested Rate: rate(prometheus_tsdb_head_samples_appended_total[1m]) to compute rate per minute. The rate function automatically handles counters resetting due to processes restarting and samples not being exactly aligned....