Merge pull request #6507 from cscib/BAEL-2460

Bael 2460
This commit is contained in:
Eric Martin 2019-03-28 07:21:46 -05:00 committed by GitHub
commit 7ac699f019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 871 additions and 0 deletions

View File

@ -32,6 +32,7 @@
<module>spring-cloud-zuul-eureka-integration</module>
<module>spring-cloud-contract</module>
<module>spring-cloud-kubernetes</module>
<module>spring-cloud-kubernetes-2</module>
<module>spring-cloud-archaius</module>
<module>spring-cloud-functions</module>
<module>spring-cloud-vault</module>

View File

@ -0,0 +1,24 @@
target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/

View File

@ -0,0 +1,5 @@
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY target/client-service-1.0-SNAPSHOT.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9999 -jar /app.jar

View File

@ -0,0 +1,8 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: client-service
data:
application.properties: |-
bean.message=Testing reload ! Message from backend is: %s <br/> Services : %s

View File

@ -0,0 +1,33 @@
kind: Service
apiVersion: v1
metadata:
name: client-service
spec:
selector:
app: client-service
ports:
- protocol: TCP
port: 8080
nodePort: 30083
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: client-service
spec:
selector:
matchLabels:
app: client-service
replicas: 1
template:
metadata:
labels:
app: client-service
spec:
containers:
- name: client-service
image: client-service:latest
imagePullPolicy: Never
ports:
- containerPort: 8080

View File

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>client-service</artifactId>
<name>client-service</name>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-kubernetes-2</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud-dependencies.version>Finchley.SR2</spring-cloud-dependencies.version>
<spring.cloud.k8s.version>1.0.0.RELEASE</spring.cloud.k8s.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-dependencies</artifactId>
<version>${spring.cloud.k8s.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-kubernetes-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.spring.cloud.kubernetes.client.Application</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,27 @@
package com.baeldung.spring.cloud.kubernetes.client;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
@SpringBootApplication
@EnableDiscoveryClient
@EnableCircuitBreaker
@RibbonClient(name = "travel-agency-service", configuration = RibbonConfiguration.class)
public class Application {
@LoadBalanced
@Bean
RestTemplate restTemplate() {
return new RestTemplate();
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.spring.cloud.kubernetes.client;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConfigurationProperties(prefix = "bean")
public class ClientConfig {
private String message = "Message from backend is: %s <br/> Services : %s";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

View File

@ -0,0 +1,54 @@
package com.baeldung.spring.cloud.kubernetes.client;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import java.net.UnknownHostException;
import java.util.List;
@RestController
public class ClientController {
@Autowired
private DiscoveryClient discoveryClient;
@Autowired
private ClientConfig config;
@Autowired
private TravelAgencyService travelAgencyService;
@RequestMapping("/deals")
public String getDeals() {
return travelAgencyService.getDeals();
}
@GetMapping
public String load() {
RestTemplate restTemplate = new RestTemplate();
String resourceUrl = "http://travel-agency-service:8080";
ResponseEntity<String> response = restTemplate.getForEntity(resourceUrl, String.class);
String serviceList = "";
if (discoveryClient != null) {
List<String> services = this.discoveryClient.getServices();
for (String service : services) {
List<ServiceInstance> instances = this.discoveryClient.getInstances(service);
serviceList += ("[" + service + " : " + ((!CollectionUtils.isEmpty(instances)) ? instances.size() : 0) + " instances ]");
}
}
return String.format(config.getMessage(), response.getBody(), serviceList);
}
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2016 to the original authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.baeldung.spring.cloud.kubernetes.client;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AvailabilityFilteringRule;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.PingUrl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
public class RibbonConfiguration {
@Autowired
IClientConfig ribbonClientConfig;
/**
* PingUrl will ping a URL to check the status of each server.
* Say Hello has, as youll recall, a method mapped to the /path; that means that Ribbon will get an HTTP 200 response when it pings a running Backend Server
*
* @param config Client configuration
* @return The URL to be used for the Ping
*/
@Bean
public IPing ribbonPing(IClientConfig config) {
return new PingUrl();
}
/**
* AvailabilityFilteringRule will use Ribbons built-in circuit breaker functionality to filter out any servers in an open-circuit state:
* if a ping fails to connect to a given server, or if it gets a read failure for the server, Ribbon will consider that server dead until it begins to respond normally.
*
* @param config Client configuration
* @return The Load Balancer rule
*/
@Bean
public IRule ribbonRule(IClientConfig config) {
return new AvailabilityFilteringRule();
}
}

View File

@ -0,0 +1,26 @@
package com.baeldung.spring.cloud.kubernetes.client;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
@Service
public class TravelAgencyService {
private final RestTemplate restTemplate;
public TravelAgencyService(RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}
@HystrixCommand(fallbackMethod = "getFallbackName", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1000") })
public String getDeals() {
return this.restTemplate.getForObject("http://travel-agency-service:8080/deals", String.class);
}
private String getFallbackName() {
return "Fallback";
}
}

View File

@ -0,0 +1,16 @@
spring:
application.name: client-service
cloud.kubernetes.reload.enabled: true
server.port: 8080
management:
endpoint:
restart:
enabled: true
health:
enabled: true
info:
enabled: true
ribbon:
http:
client:
enabled: true

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,17 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.cloud.kubernetes.client.Application;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class SpringContextIntegrationTest {
@Test
public void contextLoads() {
}
}

View File

@ -0,0 +1,34 @@
### build the repository
mvn clean install
### set docker env
eval $(minikube docker-env)
### build the docker images on minikube
cd travel-agency-service
docker build -t travel-agency-service .
cd ../client-service
docker build -t client-service .
cd ..
### secret and mongodb
kubectl delete -f secret.yaml
kubectl delete -f mongo-deployment.yaml
kubectl create -f secret.yaml
kubectl create -f mongo-deployment.yaml
### travel-agency-service
kubectl delete -f travel-agency-service/travel-agency-deployment.yaml
kubectl create -f travel-agency-service/travel-agency-deployment.yaml
### client-service
kubectl delete configmap client-service
kubectl delete -f client-service/client-service-deployment.yaml
kubectl create -f client-service/client-config.yaml
kubectl create -f client-service/client-service-deployment.yaml
# Check that the pods are running
kubectl get pods

View File

@ -0,0 +1,45 @@
apiVersion: v1
kind: Service
metadata:
labels:
app: mongo
name: mongodb-service
spec:
type: NodePort
ports:
- name: "http"
port: 27017
protocol: TCP
targetPort: 27017
selector:
service: mongo
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: mongo
spec:
replicas: 1
template:
metadata:
labels:
service: mongo
name: mongodb-service
spec:
containers:
- args:
- mongod
- --smallfiles
image: mongo:latest
name: mongo
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: db-secret
key: username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: password

View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-kubernetes-2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>spring-cloud-kubernetes-2</name>
<packaging>pom</packaging>
<properties>
<spring-boot.version>2.0.6.RELEASE</spring-boot.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>client-service</module>
<module>travel-agency-service</module>
</modules>
</project>

View File

@ -0,0 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: db-secret
data:
username: dXNlcg==
password: cDQ1NXcwcmQ=

View File

@ -0,0 +1,5 @@
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY target/travel-agency-service-1.0-SNAPSHOT.jar app.jar
ENV JAVA_OPTS=""
ENTRYPOINT exec java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9999 -jar /app.jar

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>travel-agency-service</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>com.baeldung.spring.cloud</groupId>
<artifactId>spring-cloud-kubernetes-2</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud-dependencies.version>Finchley.SR2</spring-cloud-dependencies.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud-dependencies.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.spring.cloud.kubernetes.travelagency.Application</mainClass>
<layout>JAR</layout>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,23 @@
package com.baeldung.spring.cloud.kubernetes.travelagency;
import com.baeldung.spring.cloud.kubernetes.travelagency.controller.TravelAgencyController;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application implements CommandLineRunner {
private static final Log log = LogFactory.getLog(TravelAgencyController.class);
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
public void run(String... args) throws Exception {
log.info("Travel Agency Started! ");
}
}

View File

@ -0,0 +1,55 @@
package com.baeldung.spring.cloud.kubernetes.travelagency.controller;
import com.baeldung.spring.cloud.kubernetes.travelagency.model.TravelDeal;
import com.baeldung.spring.cloud.kubernetes.travelagency.repository.TravelDealRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;
import java.util.Random;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
@RestController
public class TravelAgencyController {
@Autowired
private TravelDealRepository travelDealRepository;
private static final Log log = LogFactory.getLog(TravelAgencyController.class);
@RequestMapping(method = GET, path = "/deals")
public String deals() {
log.info("Client is requesting new deals!");
List<TravelDeal> travelDealList = travelDealRepository.findAll();
if (!travelDealList.isEmpty()) {
int randomDeal = new Random().nextInt(travelDealList.size());
return travelDealList.get(randomDeal)
.toString();
} else {
return "NO DEALS";
}
}
@RequestMapping(method = GET, path = "/")
@ResponseBody
public String get() throws UnknownHostException {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Host: ")
.append(InetAddress.getLocalHost()
.getHostName())
.append("<br/>");
stringBuilder.append("IP: ")
.append(InetAddress.getLocalHost()
.getHostAddress())
.append("<br/>");
stringBuilder.append("Type: ")
.append("Travel Agency")
.append("<br/>");
return stringBuilder.toString();
}
}

View File

@ -0,0 +1,92 @@
package com.baeldung.spring.cloud.kubernetes.travelagency.model;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.math.BigInteger;
import java.util.Date;
@Document(collection = "travel_deal")
public class TravelDeal {
@Id
private BigInteger id;
private String destination;
private String description;
@Field("deal_price")
private double dealPrice;
@Field("old_price")
private double oldPrice;
@Field("departure_date")
private Date departureDate;
@Field("arrival_date")
private Date arrivalDate;
public BigInteger getId() {
return id;
}
public void setId(BigInteger id) {
this.id = id;
}
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getDealPrice() {
return dealPrice;
}
public void setDealPrice(double dealPrice) {
this.dealPrice = dealPrice;
}
public double getOldPrice() {
return oldPrice;
}
public void setOldPrice(double oldPrice) {
this.oldPrice = oldPrice;
}
public Date getDepartureDate() {
return departureDate;
}
public void setDepartureDate(Date departureDate) {
this.departureDate = departureDate;
}
public Date getArrivalDate() {
return arrivalDate;
}
public void setArrivalDate(Date arrivalDate) {
this.arrivalDate = arrivalDate;
}
@Override
public String toString() {
return "TravelDeal{" + "id=" + id + ", destination='" + destination + '\'' + ", description='" + description + '\'' + ", dealPrice=" + dealPrice + ", oldPrice=" + oldPrice + ", departureDate=" + departureDate + ", arrivalDate=" + arrivalDate + '}';
}
}

View File

@ -0,0 +1,12 @@
package com.baeldung.spring.cloud.kubernetes.travelagency.repository;
import java.util.List;
import com.baeldung.spring.cloud.kubernetes.travelagency.model.TravelDeal;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface TravelDealRepository extends MongoRepository<TravelDeal, String> {
public List<TravelDeal> findByDestination(String destination);
}

View File

@ -0,0 +1,14 @@
spring.application.name=travel-agency-service
server.port=8080
spring.cloud.kubernetes.reload.enabled=true
spring.cloud.kubernetes.secrets.name=db-secret
spring.data.mongodb.host=mongodb-service
spring.data.mongodb.port=27017
spring.data.mongodb.database=admin
spring.data.mongodb.username=${MONGO_USERNAME}
spring.data.mongodb.password=${MONGO_PASSWORD}
management.endpoint.health.enabled=true
management.endpoint.info.enabled=true
management.endpoint.restart.enabled=true
com.baeldung.spring.cloud.kubernetes.services=debug

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProfile name="kube">
<appender name="stash" class="net.logstash.logback.appender.logstashTcpSocketAppender">
<destination>logstash:5000</destination>
<encoder class="net.logstash.logback/encoder.LogstashEncoder"/>
</appender>
<root level="INFO">
<appender-ref ref="stash"/>
</root>
</springProfile>
<springProfile name="kube, local">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="INFO"/>
</springProfile>
</configuration>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: travel-agency-service
data:
application.properties: |-
bean.message=Testing reload ! Message from backend is: %s <br/> Services : %s

View File

@ -0,0 +1,44 @@
kind: Service
apiVersion: v1
metadata:
name: travel-agency-service
spec:
selector:
app: travel-agency-service
ports:
- protocol: TCP
port: 8080
nodePort: 30081
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: travel-agency-service
spec:
selector:
matchLabels:
app: travel-agency-service
replicas: 2
template:
metadata:
labels:
app: travel-agency-service
spec:
containers:
- name: travel-agency-service
image: travel-agency-service:latest
imagePullPolicy: Never
ports:
- containerPort: 8080
env:
- name: MONGO_USERNAME
valueFrom:
secretKeyRef:
name: db-secret
key: username
- name: MONGO_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: password