I am doing a POC on Config Server wherein I will connect to BitBucket repo and if any checkin happen in that repo, my Config Service will pick those changes. In the below code if I am providing bitbucket credentials (hardcoding username and password), its able to connect to BitBucket and everything is working fine. But if I try to provide SSH key, its throwing below error:
application.yml
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${url}
cloud:
config:
server:
git:
cloneOnStart: true
username: username
password: password
default-label: master
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
Like I said the above configuration is working fine. When I replaced with the below configuration.
server.port: 8888
spring:
application.name: config-server
cloud.config.server.git.uri: ${URL}
cloud:
config:
server:
git:
#cloneOnStart: true
ignore-local-ssh-settings: true
hostKey: ${hostKEY}
hostKeyAlgorithm: ssh-rsa
private-key: ${SSH PRIVATE KEY}
management:
endpoints:
web:
exposure:
include: refresh
eureka:
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/
registryFetchIntervalSeconds: 1
instance:
leaseRenewalIntervalInSeconds: 1
I am getting below error::
2023-02-10T12:26:39.276+05:30 INFO 24628 --- [ main] c.e.c.ConfigServerApplication : Started ConfigServerApplication in 2.949 seconds (process running for 3.646)
2023-02-10T12:26:41.041+05:30 WARN 24628 --- [2)-10.73.53.175] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.
org.eclipse.jgit.api.errors.TransportException: https://bitbucketdc-cluster07.jpmchase.net/scm/ccbrft/ccbrap-config.git: Authentication is required but no CredentialsProvider has been registered
I created SSH Key using command :: ssh-keygen -m PEM -t rsa -b 4096 -C "cigfid_dev#example.com
Any help is appreciated.
Related
I have a config server in github have a structure like this:
-ms_one
|_application.yml
|_application-dev.yml
-ms_two
|_application.yml
|_application-dev.yml
Repo url: My Github Repo
In the project I also follow the same structure:
-configServer
-ms_one
-ms_two
In the application.yml of configServer I have
spring:
application:
name: CONFIGSERVER
profiles:
active: dev
cloud:
config:
server:
git:
uri: <github repo url>
clone-on-start: true
default-label: main
search-paths: {application}
eureka:
client:
fetch-registry: true
register-with-eureka: true
logging:
level:
web: error
In the ms-one service I have in application.yml
spring:
profiles:
active: dev
application:
name: ms-one
config:
import: configserver:http://localhost:8003
Now, I want the config server to fetch the configuration from the folder with the same name as application name and apply the configuration. The problem is the correct configuration is not being fetched. Please help me doing this
I got the idea of setting spring.cloud.config.server.git.search-paths:{application} from the thread How to point spring-cloud-config server to a git folder inside a git repo
I have a Spring Boot Application and I would like to Load configurations from Vault based on the Profile I am running. At present i have 2 profiles (dev, prod). My Dev Profile uses a H2 database where as the Prod Profile uses a Posgres DB. Running the dev Profile loads the correct config from Vault but running with the Prod Profile seems to be skipping it somehow and not looking in Vault.
bootstrap.yaml
spring:
application:
name: my-app
profiles:
active:
cloud:
vault:
host: localhost
port: 8200
scheme: http
uri: http://localhost:8200
connection-timeout: 5000
read-timeout: 15000
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000
kv:
enabled: true
backend: secret
default-context: my-app/dev
fail-fast: false
bootstrap-prod.yaml
spring:
application:
name: gateway
profiles:
active: prod
cloud:
vault:
host: localhost
port: 8200
scheme: http
uri: http://localhost:8200
connection-timeout: 5000
read-timeout: 15000
authentication: TOKEN
token: 00000000-0000-0000-0000-000000000000
kv:
enabled: true
backend: secret
default-context: my-app/dev
fail-fast: false
For example running the command gradle will load configuration from vault. But running gradle -Pprod fails to load the correct configuration from Vault.
try this syntax to activate your profile when using gradle:
./gradlew clean bootRun --args='--spring.profiles.active=prod'
I currently have two microservices:
- service - port 8080, this microservice tries to fetch config from the other microservice.
- config - port 8888, this microservice is supposed to provide config.
For some reason my service is unable to fetch configuration from config microservice.
My config microservice should work because I can curl localhost:8888/service/default on my machine I receive:
{"name":"service","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[{"name":"classpath:/shared/service.yml","source":{"server.port":8080,"spring.security.user.password":"admin"}},{"name":"classpath:/shared/service.yaml","source":{"server.port":8080,"spring.security.user.password":"admin"}}]}
Error received (full)
service | 2019-06-06 21:31:06.721 INFO 1 --- [main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://config:8888
service | 2019-06-06 21:31:06.894 INFO 1 --- [main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://config:8888. Will be trying the next url if available
service | 2019-06-06 21:31:06.904 ERROR 1 --- [main] o.s.boot.SpringApplication : Application run failed
Docker-compose.yaml
version: '3.7'
services:
config:
container_name: config
build: ./config
ports:
- 8888:8888
service:
container_name: service
build: ./service
ports:
- 8080:8080
depends_on:
- config
Service Dockerfile:
FROM openjdk:8-jdk-alpine
ADD target/service.jar /app.jar
CMD [ "java", "-Xmx200m", "-jar", "/app.jar" ]
EXPOSE 8080
Service bootstrap.yaml
spring:
application:
name: service
cloud:
config:
uri: http://config:8888
fail-fast: true
service.yaml (has service configuration)
server:
port: 8080
spring:
security:
user:
password: admin # doesnt set since no connection
Config Dockerfile
FROM openjdk:8-jdk-alpine
ADD target/config.jar /app.jar
CMD [ "java", "-Xmx200m", "-jar", "/app.jar" ]
EXPOSE 8888
Config application.yaml
spring:
application:
name: config
profiles:
active: composite
cloud:
config:
server:
composite:
- type: native
search-locations: classpath:/shared
server:
port: 8888
shared/service.yaml (has service configuration)
server:
port: 8080
spring:
security:
user:
password: admin # doesnt set since no connection
Any ideas?
I found some similar issues, although they only had issues with their URI, mine is set correctly.
Microservice can not reach to Config Server on Docker Compose
Docker - SpringConfig - Connection refused to ConfigServer
When one service depends on another you have to make sure that the latter is fully started before connecting to it.
In your case, most probably, config is started but not ready (context started) at the time service is run. As #Ganesh Karewad and #asolanki pointed out, a solution is to implement a reconnection logic. Another solution is to make sure config is initialized and accepting connections before you run service.
You can achieve that with a script that waits until the config app is up. In alternative you could configure the config container with a health check command and after you start it, wait until it is marked as healthy. Then you can run the service container.
Similar issue discussed here and here
Hope that helps.
I'm following this article (http://www.baeldung.com/spring-cloud-netflix-eureka) to set up eureka, my application.yml looks like this
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}
but I debug the main application I always get:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.4.10.jar:1.4.10]
and when I got to my browser eureka is not in 8761 port but in 8080 port instead, what I'm doing wrong?
You can't referece a property you just set above. This is not a procedural script, there's no guarantee the eureka line will be executed before the server one so ${server.port} will be the defaut: 8080
If you run you app using an environment prop it will work. Try:
java -Dserver.port=8761 -jar your-app.jar
Currently I'm working in Spring boot micro services project. Consider I have 3 micro services named as A, B, C. Now My project have application.yml file separately for each micro service. Now I want to add one more microservice D, for manage all service property files.
view my config-service structure
eureka.yml(inside config-service) file is:
server:
port: 8761
eureka:
client:
registerWithEureka: false
fetchRegistry: false
server:
waitTimeInMsWhenSyncEmpty: 0
endpoints:
sensitive: false
In eureka-service bootstrap.properties is:
spring:
application:
name: eureka
cloud:
config:
uri: http://localhost:8888
Config service application properties :
spring:
application:
name: config
cloud:
config:
server:
native:
search-locations: classpath:/config/DEVELOP
profiles:
active: native
server:
port: 8888
my config application file is:
#SpringBootApplication
#EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
I did the following steps:
start the config-service
start the eureka-service
unfortunately, eureka server getting error.
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
the problem is while running eureka server, its not looking the config file which is inside the config service...
help me to resolve this. or instead of micro service, how can I go with folder?
Thanks # g00glen00b
I am changed config service bootstrap yml as follows :
spring:
application:
name: config
cloud:
config:
server:
native:
searchLocations: classpath:/config/DEVELOP/
profiles:
active: native
server:
port: 8888
Its working fine.