#37: Document how to make the namespace available to the pod. Add warning to the logs if namespace is unknown. Expose namespace through the pod health indiciator.
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -76,6 +76,7 @@
|
||||
|
||||
<properties>
|
||||
<!-- Dependency Versions -->
|
||||
<commons-logging.version>1.2</commons-logging.version>
|
||||
<kubernetes-client.version>1.3.83</kubernetes-client.version>
|
||||
<lombok.version>1.16.8</lombok.version>
|
||||
<servlet-api.version>2.5</servlet-api.version>
|
||||
@@ -205,6 +206,12 @@
|
||||
<version>${servlet-api.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>${commons-logging.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
||||
11
readme.md
11
readme.md
@@ -183,6 +183,17 @@ An alternative approach that provides more direct Archaius support without getti
|
||||
This module allows you to annotate your application with the `@ArchaiusConfigMapSource` and archaius will automatically use the configmap as a watched source *(get notification on changes)*.
|
||||
|
||||
---
|
||||
### Troubleshooting
|
||||
|
||||
Most of the components provided in this project need to know the namespace. For Kubernetes (1.3+) the namespace is made available to pod as part of the service account secret and automatically detected by the client.
|
||||
For earlier version it needs to be specified as an env var to the pod. A quick way to do this is:
|
||||
|
||||
env:
|
||||
- name: "KUBERNETES_NAMESPACE"
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: "metadata.namespace"
|
||||
|
||||
### Building
|
||||
|
||||
You can just use maven to build it from sources:
|
||||
|
||||
@@ -55,6 +55,11 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Testing Dependencies -->
|
||||
<dependency>
|
||||
|
||||
@@ -20,6 +20,8 @@ import io.fabric8.kubernetes.client.Config;
|
||||
import io.fabric8.kubernetes.client.ConfigBuilder;
|
||||
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
|
||||
import io.fabric8.kubernetes.client.KubernetesClient;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
@@ -32,6 +34,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
@EnableConfigurationProperties(KubernetesClientProperties.class)
|
||||
public class KubernetesAutoConfiguration {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(KubernetesClientProperties.class);
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(Config.class)
|
||||
public Config kubernetesClientConfig(KubernetesClientProperties kubernetesClientProperties) {
|
||||
@@ -62,6 +66,9 @@ public class KubernetesAutoConfiguration {
|
||||
.withTrustCerts(or(kubernetesClientProperties.isTrustCerts(), base.isTrustCerts()))
|
||||
.build();
|
||||
|
||||
if (properties.getNamespace() == null || properties.getNamespace().isEmpty()) {
|
||||
LOG.warn("No namespace has been detected. Please specify KUBERNETES_NAMESPACE env var, or use a later kubernetes version (1.3 or later)");
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ public class KubernetesHealthIndicator extends AbstractHealthIndicator {
|
||||
if (current != null) {
|
||||
builder.up()
|
||||
.withDetail("inside", true)
|
||||
.withDetail("namespace", current.getMetadata().getNamespace())
|
||||
.withDetail("podName", current.getMetadata().getName())
|
||||
.withDetail("podIp", current.getStatus().getPodIP())
|
||||
.withDetail("serviceAccount", current.getSpec().getServiceAccountName())
|
||||
|
||||
Reference in New Issue
Block a user