Microserve + docker + kubernates
Microserve + docker + kubernates
1. Monolithic:
Adv :
1. It is best for small project or app
2. fewer cross-cutting concerns like logging, auditing
3. better performance due to no network latency.
DisAdv :
1. Not able to adopt new technologies
2. single code on single server with one database
3. tiny update need full deployment
4. any change will affect other layers.
2. SOA – Service oriented Architecture
Adv :
1. we can make different services on different server
2. better maintainability and reliability and parallel development.
DisAdv:
1. Complex management due to maintain proxy for connecting all services and SOAP
webservices.
2. high investment costs because using enterprise oracle service bus and extra
overload.
3. Microservices:
Adv :
1. Easy to develop, test and deploy
2. Parallel development
3. Ability to scale horizontally like you want to scale one of your services you can do
easily
DisAdv :
1. Complexity – manage all instances of servers but this can be solved by azure, aws,
docker etc.
2. Infrastructure overhead and security concerns.
To run spring boot project on cmd
- mvn clean install
- mvn spring-boot:run
if not mvn use java = java -jar target/Accounts-0.0.1-SNAPSHOT.jar
1. Accounts :
Create Dockerfile ouside src folder
Create images : docker images
docker build . -t ingleajay/accounts
docker image inspect imageid
docker run -p 8081:8080 ingleajay/accounts
docker ps = for containers view
docker stop containerid = stop container
docker logs containerid = app logs
docker start containerid1 containerid2
docker container pause containerid
docker container unpause containerid
docker container inspect containerid
docker stats
docker rm container id
docker image imageid
accounts:
image: ingleajay/account:latest
mem_limit: 700m
ports:
- "8080:8080"
networks:
- ingleajay-network
loans:
image: ingleajay/loans:latest
mem_limit: 700m
ports:
- "8090:8090"
networks:
- ingleajay-network
cards:
image: ingleajay/cards:latest
mem_limit: 700m
ports:
- "9000:9000"
networks:
- ingleajay-network
networks:
ingleajay-network:
docker-compose up = with this commands all services will run
docker-compose stop
1. codebase – each microservice has it’s own code base like github like accounts and
cards are github different
2. dependencies – each microservices has pom.xml and maven or gradle
3. config – it’s store env specific configurations from your code
4. Backing service – change local connections to third party change lke db from local to
aws db
5. Build,release, run – it will be like after docker is build it should go in next stage that
release & that is different than build stage
6. Processes – if microservice has chaining call for end to end results then it should be
persist and has stateful services
7. Port binding – all different micoservices has their own ports
8. Concurrency – when we want to scale up and scale down size of ram then we always
follow horizontal approach like it crease instances of app but vertical approach will
increase size of hardware
9. Disposability – if microservice is failing to run then that microservice will be
disposable and new instance is created
10.Dev/prod parity – we should not change anything in this env manually because it will
create problems later.
11.Logs – maintaine logs of each app
12.Admin process – clean up and migrations task
http:localhost:8071/cards/prod
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
3. Add models class like Properties :
@Getter
@Setter
public class Properties {
private String msg;
private String buildVersion;
private Map<String, String> mailDetails;
private List<String> activeBranches;
}
5. Add Controller :
@Autowired
AccountsServiceConfig accountsConfig;
@GetMapping("/account/properties")
public String getPropertyDetails() throws JsonProcessingException {
ObjectWriter ow = new
ObjectMapper().writer().withDefaultPrettyPrinter();
Properties properties = new Properties(accountsConfig.getMsg(),
accountsConfig.getBuildVersion(),
accountsConfig.getMailDetails(),
accountsConfig.getActiveBranches());
String jsonStr = ow.writeValueAsString(properties);
return jsonStr;
}
URL : http://localhost:8080/accounts/properties
version: "2.6"
services:
configserver:
image: ingleajay/configserver:latest
mem_limit: 700m
ports:
- "8071:8071"
networks:
- ingleajay
accounts:
image: ingleajay/account:latest
mem_limit: 700m
ports:
- "8080:8080"
networks:
- ingleajay
depends_on:
- configserver
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
environment:
SPRING_PROFILES_ACTIVE: prod
SPRING_CONFIG_IMPORT: configserver:http://configserver:8071/
loans:
image: ingleajay/loans:latest
mem_limit: 700m
ports:
- "8090:8090"
networks:
- ingleajay
depends_on:
- configserver
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
environment:
SPRING_PROFILES_ACTIVE: prod
SPRING_CONFIG_IMPORT: configserver:http://configserver:8071/
cards:
image: ingleajay/cards:latest
mem_limit: 700m
ports:
- "9000:9000"
networks:
- ingleajay
depends_on:
- configserver
deploy:
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
window: 120s
environment:
SPRING_PROFILES_ACTIVE: prod
SPRING_CONFIG_IMPORT: configserver:http://configserver:8071/
networks:
ingleajay:
@RefreshScope : this is for without restarting server it
will take updated properties
encrypt.key=ajayingle
this is used when we want to keep our info is encryted so
first you have to hit below url and get code
Post : as body pass text “welcome to loan prod” : localhost:8071/encrypt
you will get code then paste that code into github after that you can
check by localhost:8071/decrypt you will get your text
It will Next Challenge : how one microservice connects with other microservices like
accounts wants to connect with loan then how it can be communicated
Load balanced is for change your starting name from your end point like
localhost:8080/account = AccountService/account
Genrate euraka server by adding config-cloud, eureka server…
Add in app properties:
spring.application.name=eurekaserver
spring.config.import=optional:configserver:http://
localhost:8071/
spring.cloud.loadbalancer.ribbon.enabled=false
server.port=8070
eureka.instance.hostname=localhost
eureka.client.registerWithEureka=false
eureka.client.fetchRegistry=false
eureka.client.serviceUrl.defaultZone=http://$
{eureka.instance.hostname}:${server.port}/eureka/
App prop :
management.endpoint.shutdown.enabled=true
endpoints.shutdown.enabled=true
eureka.instance.preferIpAddress = true
eureka.client.registerWithEureka = true
eureka.client.fetchRegistry = true
eureka.client.serviceUrl.defaultZone =
http://localhost:8070/eureka/