I'm new in kuberntes.
I'm trying to deploy a spring boot application on my local machine with minikube. But i keep getting this error:
Can't read configMap with name: [spring-mongo-service] in namespace:[default]. Ignoring.
I'm using this pom file as configuration for spring boot application:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-all</artifactId>
</dependency>
<dependency>
<groupId>com.github.piomin</groupId>
<artifactId>spring-cloud-kubernetes-discovery-ext</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
Themain class is:
@SpringBootApplication
@EnableDiscoveryClient
public class MongoExampleApplication {
public static void main(String[] args) {
SpringApplication.run(MongoExampleApplication.class, args);
}
}
The configMap file is:
kind: ConfigMap
metadata:
name: mongo-conf
data:
host: mongodb-service
database: admin ```
My secrets file is:
```apiVersion: v1
kind: Secret
metadata:
name: mongo-secret
data:
username: dGVzdA==
password: dGVzdEAxMjM=
The data base deployement file is:
apiVersion: v1
kind: Service
metadata:
labels:
app: mongo
name: mongodb-service
spec:
ports:
- port: 27017
targetPort: 27017
selector:
app: mongo
clusterIP: None # We Use DNS, Thus ClusterIP is not relevant
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mongo-pv-claim # name of PVC essential for identifying the storage data
labels:
app: mongo
tier: database
spec:
accessModes:
- ReadWriteOnce #This specifies the mode of the claim that we are trying to create.
resources:
requests:
storage: 1Gi #This will tell kubernetes about the amount of space we are trying to claim.
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mongo
labels:
app: mongo
spec:
selector:
matchLabels:
app: mongo
replicas: 1
template:
metadata:
labels:
app: mongo
name: mongodb-service
spec:
containers:
- image: mongo:latest
name: mongo
env:
- name: MONGO_INITDB_ROOT_USERNAME
valueFrom:
secretKeyRef:
name: mongo-secret
key: username
- name: MONGO_INITDB_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-secret
key: password
ports:
- containerPort: 27017
name: mongo
volumeMounts:
- name: mongo-persistent-storage
mountPath: /data/db #This is the path in the container on which the mounting will take place.
volumes:
- name: mongo-persistent-storage # Obtaining 'vloume' from PVC
persistentVolumeClaim:
claimName: mongo-pv-claim
The database pod is working perfectly And the spring deployement file is:
kind: Service
apiVersion: v1
metadata:
name: spring-mongo-service
spec:
selector:
app: spring-mongo-service
ports:
- protocol: TCP
port: 8080
nodePort: 30081
type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-mongo-service
spec:
selector:
matchLabels:
app: spring-mongo-service
replicas: 2
template:
metadata:
labels:
app: spring-mongo-service
spec:
containers:
- name: spring-mongo-service
image: damdoum97/mongoed:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
- name: MONGO_USERNAME
valueFrom:
secretKeyRef:
name: mongo-secret
key: username
- name: MONGO_PASSWORD
valueFrom:
secretKeyRef:
name: mongo-secret
key: password
- name: MONGO_DB
valueFrom:
configMapKeyRef:
name: mongo-conf
key: database
- name: MONGO_HOST
valueFrom:
configMapKeyRef:
name: mongo-conf
key: host
the application.yml file is:
spring:
application:
name: spring-mongo-service
data:
mongodb:
host: '${MONGO_HOST}'
database: '${MONGO_DB}'
port: 27017
username: '${MONGO_USERNAME}'
password: '${MONGO_PASSWORD}'
cloud:
kubernetes:
discovery:
register: true
secrets:
name: mongo-secret
config:
enabled: true
sources:
- namespace: default
name: mongo-conf
reload:
enabled: true
mode: polling
period: 1000
management:
endpoint:
restart:
enabled: true
health:
enabled: true
info:
enabled: true
Am I missing something here? Am I using the right dependencies ?