Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

lucasnscr
lucasnscr

Posted on

     

Deployment spring application in Kubernetes with minikube

Kubernetes, Spring and Docker

Project description

🚀 This project aims to create an application withmicroservices architecture usingSpring for all development. Forvirtualization,Docker is used to support our database allocation and createapplication containers. Toorchestrate our container,Kubernetes is used withMinikube that provides us with all the context of a container cluster to receive our application and its surroundings.

Here is the complete code of the project

Installation and Technologies

The following technologies were used to carry out the project and it is necessary to install some items:

  • Docker
  • Java 11
  • Maven
  • MiniKube
  • Spring
  • Postgres
  • Docker

Kubernetes

Kubernetes is aportable,extensible,open-source platform for managing containerized workloads and services, that facilitates both declarative configuration and automation. It has a large, rapidly growing ecosystem. Kubernetes services, support, and tools are widely available.

Currently, k8s isone of the main DevOps tools, as it is normally used in production environments and application approval. However, it is also possible tocreate a local cluster on a development machine, which greatlyfacilitates the local testing of an application and also increases the reliability of a new development, since the programming environment is much closer to the development environment. production.

What are Pods?

Pods are thesmallest deployable units of computing that you can create and manage in Kubernetes.

A Pod (as in a pod of whales or pea pod) is a group of one or more containers, with shared storage and network resources, and a specificationfor how to run the containers. A Pod's contents are always co-located and co-scheduled, and run in a shared context. A Pod models an application-specific "logical host": it contains one or more application containers which are relatively tightly coupled.In non-cloud contexts, applications executed on the same physical or virtual machine are analogous to cloud applications executed on the same logical host.

What are ConfigMaps ?

AConfigMap is an API object used to store non-confidential data in key-value pairs. Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume. A ConfigMap allows you to decouple environment-specific configuration from your container images, so that your applications are easily portable.

About Project

The project has a Spotify plugin to automatically generate the docker image. Every project has itsDockerfile. To generate the service image, you will need to run two commands.

mvn clean installmvn dockerfile:build
Enter fullscreen modeExit fullscreen mode

After generating the artifacts you will need toinstall MiniKube andkubectl, assuming that these two items are already configured correctly, we select three commands, one to start the kubernetes cluster, enable the kubernetes dashboard that allows tracking the cluster with a visual interface and the other to stop it.

minikube startminikube dashboardminikube stop
Enter fullscreen modeExit fullscreen mode

For you to be** able to deploy your pods with local docker images**, you will need to run the command below.

eval $(minikube -p minikube docker-env)
Enter fullscreen modeExit fullscreen mode

This command directs your minikube to use your local docker-env address in that terminal instance, so your pods will be uploaded using images that have already been built locally without necessarily being on DockerHub or some other image repository.

With the cluster initialized, there are some commands that are important for us tosee our pods, deployments, services and etc. Below are two examples of commands to get what is operating in the cluster:

kubectl get podskubectl get services
Enter fullscreen modeExit fullscreen mode

Our application uses the Postgres database, there is a directory within the projectto make the database available on the cluster, you need to run the commands below in sequence:

kubectl create  -f  postgres.yamlkubectl create  -f  postgres-service.yamlkubectl port-forward svc/postgres 5000:5432kubectl create -f config-map.yaml
Enter fullscreen modeExit fullscreen mode

The respective commands create a deployment, a service, perform a database port forwarding inside k8s and create a configmap for the database.

Deploying the application on Kubernetes

After preparing our dependencies, we willdeploy our three services that make up the application. Each service will have a directory with the files related to the creation of config map, deployments and services.This is an important order to keep for the perfect execution of services on k8s.

kubectl create -f configmap.yamlkubectl create -f deployment.yamlkubectl create -f service.yaml
Enter fullscreen modeExit fullscreen mode

Running everything in this sequence will successfully run the services in Kubernetes. In casesomething fails here follow some commands to kill the pod, the deployment and the service.

kubectl delete deploymentkubectl delete service
Enter fullscreen modeExit fullscreen mode

Finally, to follow thelogs of your application, you need to run the command:

kubectl logs {pod name}
Enter fullscreen modeExit fullscreen mode

Here we finish aProject with three microservices and a database all running inside the Kubernetes cluster, where we can manage services and functionalities provided by the cluster.

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
roshan_404 profile image
Roshan
  • Joined

Can you put this on YouTube, i think this would be helpful to many..
I am working on the same technologies and needed this kind of hands-on to get started...
I am not that experienced to judge your work but it is a great post..

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Software Engineer and Photographer in his spare time
  • Work
    Platform Tech Manager | Software Engineer
  • Joined

More fromlucasnscr

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp