EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login
Home Software Development Software Development Tutorials Spring Tutorial Spring Cloud Kubernetes
Secondary Sidebar
Spring Tutorial
  • Spring Cloud Basics
    • What is Spring Cloud
    • Spring Cloud Contract
    • Spring Cloud Components
    • Spring Cloud Version
    • Spring Cloud Data Flow
    • Spring cloud stream
    • Spring Cloud Dependencies
    • Spring cloud microservices
    • spring cloud gateway
    • Spring Cloud Config
    • Spring Cloud Kubernetes
    • Spring Cloud Sleuth
  • Spring
    • What is Spring Framework?
    • Spring Architecture
    • What is Spring Integration?
    • IoC Containers
    • What is AOP?
    • Spring Modules
    • Spring Batch Processing
    • Spring Batch Partitioner
    • Spring Batch Job
    • Spring AOP
    • Spring Expression Language
    • Dependency Injection in Spring
    • Spring Batch Architecture
    • Spring framework Interview Questions
  • Spring Boot
    • What is Spring Boot
    • Spring Boot flyway
    • Spring Boot framework
    • Spring Boot Logback
    • Spring Boot actuator endpoints
    • Spring Boot gRPC
    • Spring Boot jdbctemplate example
    • Spring Boot ehcache
    • Spring Boot Architecture
    • Spring Boot Port
    • Introduction of spring boot
    • Spring Boot ide
    • Spring Boot Netty
    • Spring Boot ORM
    • Spring Boot Versions
    • Spring Boot JUnit
    • Spring Boot Keycloak
    • Spring Boot gradle
    • Spring Boot Lombok
    • Spring Boot autowired
    • Spring Boot bean
    • Spring Boot hibernate
    • Spring Boot integration test
    • Spring Boot jdbc
    • Spring Boot MongoDB
    • Spring Boot postgresql
    • Spring Boot rest
    • Spring Boot swagger
    • Spring Boot thymeleaf
    • Spring Boot Unit Test
    • Spring Boot Webflux
    • Spring Boot webclient
    • Spring Boot kubernetes
    • Spring Boot Properties
    • Spring Boot Validation
    • Spring Boot Feature
    • Spring Boot Application
    • Spring Boot email
    • Spring Boot MVC
    • Spring Boot Exception Handling
    • Spring Boot Starter Parent
    • Spring Boot Docker
    • Spring Boot Logging
    • Spring Boot Query
    • Spring Boot Multiple Data Sources
    • Spring Boot Basic Authentication
    • Spring Boot Test
    • Spring Boot jwt
    • Spring Boot Liquibase
    • Spring Boot Prometheus
    • Spring Boot debug
    • Spring Boot GraalVM
    • Spring Boot Batch
    • Spring Boot controller
    • Spring Boot CLI
    • Spring Boot file upload
    • Spring Boot interceptor
    • Spring Boot Service
    • Spring Boot Configuration
    • Spring Boot Datasource Configuration
    • Spring Boot Annotations
    • Spring Boot Starter We
    • Spring Boot Actuator
    • Spring Boot DevTools
    • Spring Boot Repository
    • Spring Boot Dependencies
    • Spring Boot Path Variable
    • Spring Boot Microservices
    • Spring Boot Run Command
    • Spring Boot application.properties
    • Spring Boot Transaction Management
    • Spring Boot Banner
    • Spring Boot JPA
    • Spring Boot Change Port
    • Spring Boot RestTemplate
    • Spring Boot cors
    • Spring Boot HTTPS
    • Spring Boot OAuth2
    • Spring Boot Profiles
    • Spring Boot Interview Questions
    • Spring Boot filter
    • Spring boot logging level
    • Spring Boot Cache
    • Spring Boot Advantages
    • Spring Boot Scheduler
    • Spring Boot Initializr
    • Spring Boot Maven
    • Spring Boot Admin
    • Spring Boot Tomcat
    • Spring Boot WebSocket
    • Spring Boot Executable Jar
    • Spring Boot CommandLineRunner
    • Spring Boot DataSource
    • Spring Batch Scheduler
    • Spring Batch Example
    • Spring Batch Tasklet
    • Spring Batch Admin
    • Spring Batch
    • Spring Boot Qualifier
    • Spring Boot War
    • Spring Boot Test Configuration

Related Courses

Spring Boot Certification Course

Spring Framework Course Training

All in One Data Science Course

Spring Cloud Kubernetes

Spring Cloud Kubernetes

Definition of Spring Cloud Kubernetes

Spring Cloud Kubernetes provides Spring Cloud interface implementations which was allowing developers to construct and run Spring Cloud applications on Kubernetes. While this project may be handy when developing a cloud-native application. It is not required to deploy the Spring Boot application on Kubernetes. If we are just getting started with Kubernetes and Spring Boot, we can get a lot done with only a basic Spring Boot app and Kubernetes.

Spring cloud Kubernetes overviews

  • Spring Cloud and Kubernetes are two prominent tools that can be used for a variety of purposes.
  • Micro services architecture, on the other hand, is sometimes referred to as a competitive solution.
  • Both Spring Cloud and Kubernetes are excellent choices for building a micro services solution since they include components that address the most prevalent issues.
  • If we chose Kubernetes as our main container manager and deployment platform, we can still take advantage of Spring Cloud’s useful capabilities, mostly through the Spring Cloud Kubernetes project.
  • This new project makes it simple to integrate Spring Boot apps with Kubernetes. It’s a good idea to look at how to deploy a Spring Boot application on Minikube, a local Kubernetes environment.
  • Kubernetes is a containerized application platform for scaling, executing, and managing them. The setup and orchestration are done on the platform, not in the application.
  • Etcd is one of the most crucial Kubernetes components. All cluster data, including the service registry and application configuration, is stored in that highly accessible key-value store.
  • We won’t be able to replace it with another tool. Third-party components such as Istio or Linkerd can be used to implement more advanced routing and load balancing schemes.
  • We don’t need to add anything to the source code to deploy and execute applications on Kubernetes.
  • The project was still in its infancy when we are transferring our microservices to OpenShift. Because we didn’t have any other viable options, we decided to remove the components for discovery and configuration from the Spring Boot application.
  • Other Spring Cloud components, such as Ribbon, Sleuth, and OpenFeign were still available.
  • One of the most popular Spring Cloud projects now is in Spring Cloud Kubernetes. It may be unsurprising that it isn’t up to speed with the latest Spring Cloud features in this situation.
  • It still utilizes Ribbon instead of the new Spring Cloud Load Balancer, for example. It includes some handy tools for deploying Spring Boot applications on Kubernetes.

Spring Cloud Kubernetes create a Secret

The below example shows to create secrets which are as follows.

1) Create project template by using spring initializer

In the below step we have provided project group name as com. example, artifact name as springcloudkubernetes, project name as springcloudkubernetes, and selected java version as 8.

In the below project, we have selected spring web dependency to implement the project.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

All in One Software Development Bundle(600+ Courses, 50+ projects)
Python TutorialC SharpJavaJavaScript
C Plus PlusSoftware TestingSQLKali Linux
Price
View Courses
600+ Online Courses | 50+ projects | 3000+ Hours | Verifiable Certificates | Lifetime Access
4.6 (86,754 ratings)

Group – com. example Artifact name – springcloudkubernetes
Name – springcloudkubernetes Spring boot – 2.6.0
Project – Maven Java – 8
Dependencies – spring web
Package name - com. example.springcloudkubernetes
Project Description - Project for springcloudkubernetes

ok

2) After generating project extract files and open this project by using spring tool suite –

After generating the project by using spring initializer in this step we are extracting the jar file and opening project by using spring tool suite.

10

3) After opening project using spring tool suite check the project and its files –

In this step, we are checking all the project template files. We also need to check maven dependencies and system libraries.

11

4) Add dependency packages –

In this step, we are adding the Kubernetes dependency in the project.

Code:

<dependency> -- Start of dependency tag.
<groupId>org.springframework.cloud</groupId> -- Start and end of groupId tag.
<artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId> -- Start and end of artifactId tag.
</dependency> -- End of dependency tag.

12

5) Start the single node kubernetes cluster –

In this step, we are staring single-node Kubernetes cluster using minikube.

# minikube start –vm-driver-virtualbox

13

6) Switch the context –

The default context is minikube in the below step we have switched the context.

# kubectl config use-context minikube

14

7) Start the dashboard –

  • After switching the context in this step we are starting the dashboard of Kubernetes to monitor services, logs, secrets, and pods.

# minikube dashboard

1

2

8) Build the project –

  • In this step, we are building the spring cloud Kubernetes project using the following command or by using the spring tool suite.

# mvn clean install

3

9) Check the pods are running on dashboard –

  • In this step, we are checking all pods are running without any error.

4

10) Create a main class of project –

  • In this step, we are creating the main class of the application.

Code:

@SpringBootApplication
@EnableDiscoveryClient
public class springcloudkubernetes {
public static void main(String[] args) {
SpringApplication.run (springcloudkubernetes.class, args);
}
}

5

11) Create rest controller –

Code:

@RestController
public class Controller {
@Autowired
private springClient sClient;
}

6

12) Create configuration class –

Code:

@Configuration
@ConfigurationProperties (prefix = "bean")
public class config
{
private String string = "spring cloud kubernetes"
}

Spring Cloud Kubernetes 7

13) Create client controller –

Code:

@RestController
public class clientcontroller {
@Autowired
private config con;
@GetMapping
public String load() {
return String.format (config.getMessage(), "", "");
}
}

Spring Cloud Kubernetes 8

14) Create secret –

Code:

apiVersion: v1
kind: Secret
metadata:
name: database-secret
data:
username: cYVmrk==
password: cCU4BSiolfX=

Spring Cloud Kubernetes 9

15) Create mongodb service –

Code:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mongo
spec:
replicas: 1
template:
metadata:
labels:
service: mongo
name: service
spec:
containers:
- args:
- mongod
- --smallfiles
image: mongo:new
name: mongo
env:
- name: USERNAME
valueFrom:
secretKeyRef:
name: database-secret
key: username

Spring Cloud Kubernetes 10

16) Setup mongodb service –

Code:

spring.cloud.kubernetes.secrets.name=database-secret
spring.data.mongodb.host=service
spring.data.mongodb.port=27017
spring.data.mongodb.database=admin
spring.data.mongodb.username=${kubernetes}
spring.data.mongodb.password=${kubernetes}

Spring Cloud Kubernetes 11

17) Run the application and check dashboard –

Spring Cloud Kubernetes 12

Spring Cloud Kubernetes 14

Conclusion

Spring cloud Kubernetes are using microservices design patterns including distributed configuration, service discovery, circuit breaking, and load balancing. Spring Cloud Kubernetes provides Spring Cloud interface implementations which was allowing developers to construct and run Spring Cloud applications on Kubernetes.

Recommended Articles

This is a guide to Spring Cloud Kubernetes. Here we discuss the definition, overviews, create a Secret, Examples, and applications. You may also have a look at the following articles to learn more –

  1. Spring Boot Tomcat
  2. Spring Boot WebSocket
  3. spring boot gradle
  4. Spring Boot Admin
Popular Course in this category
Spring Boot Training Program (2 Courses, 3 Project)
  2 Online Courses |  3 Hands-on Projects |  22+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Spring Framework Training (4 Courses, 6 Projects)4.9
All in One Data Science Bundle (360+ Courses, 50+ projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Software Development Course

C# Programming, Conditional Constructs, Loops, Arrays, OOPS Concept

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more