or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

api-groups.mdclient-configuration.mdcore-resources.mdcustom-resources.mdexception-handling.mdindex.mdpod-operations.mdutilities.mdwatch-informers.md

client-configuration.mddocs/

0

# Client Configuration

1

2

The Fabric8 Kubernetes Client provides flexible configuration options for connecting to Kubernetes clusters. Configuration can be auto-discovered from kubeconfig files, environment variables, or explicitly set through the Config and ConfigBuilder classes.

3

4

## Core Configuration Classes

5

6

### Config Class

7

8

```java { .api }

9

public class Config {

10

// Factory methods

11

public static Config empty();

12

public static Config autoConfigure(String context);

13

public static Config fromKubeconfig(String kubeconfigContents);

14

public static Config fromKubeconfig(File kubeconfigFile);

15

public static Config fromKubeconfig(String context, File kubeconfig);

16

public static ConfigBuilder builder();

17

18

// Connection settings

19

public String getMasterUrl();

20

public String getApiVersion();

21

public String getNamespace();

22

23

// Authentication

24

public String getUsername();

25

public String getPassword();

26

public String getOauthToken();

27

public String getCaCertFile();

28

public String getCaCertData();

29

public String getClientCertFile();

30

public String getClientCertData();

31

public String getClientKeyFile();

32

public String getClientKeyData();

33

public String getClientKeyAlgo();

34

public String getClientKeyPassphrase();

35

36

// Timeouts and limits

37

public int getConnectionTimeout();

38

public int getRequestTimeout();

39

public int getUploadRequestTimeout();

40

public int getWatchReconnectInterval();

41

public int getWatchReconnectLimit();

42

public long getWebsocketPingInterval();

43

44

// Security settings

45

public Boolean isTrustCerts();

46

public Boolean isDisableHostnameVerification();

47

48

// HTTP settings

49

public String getHttpProxy();

50

public String getHttpsProxy();

51

public String[] getNoProxy();

52

public String getProxyUsername();

53

public String getProxyPassword();

54

55

// Configuration management

56

public Config refresh();

57

public File getFile();

58

public File getFileWithCluster();

59

public File getFileWithAuthInfo();

60

public List<NamedContext> getContexts();

61

public NamedContext getCurrentContext();

62

public void setCurrentContext(NamedContext context);

63

}

64

```

65

66

### ConfigBuilder Class

67

68

```java { .api }

69

public class ConfigBuilder {

70

// Connection configuration

71

public ConfigBuilder withMasterUrl(String masterUrl);

72

public ConfigBuilder withApiVersion(String apiVersion);

73

public ConfigBuilder withNamespace(String namespace);

74

75

// Authentication

76

public ConfigBuilder withUsername(String username);

77

public ConfigBuilder withPassword(String password);

78

public ConfigBuilder withOauthToken(String oauthToken);

79

public ConfigBuilder withCaCertFile(String caCertFile);

80

public ConfigBuilder withCaCertData(String caCertData);

81

public ConfigBuilder withClientCertFile(String clientCertFile);

82

public ConfigBuilder withClientCertData(String clientCertData);

83

public ConfigBuilder withClientKeyFile(String clientKeyFile);

84

public ConfigBuilder withClientKeyData(String clientKeyData);

85

public ConfigBuilder withClientKeyAlgo(String clientKeyAlgo);

86

public ConfigBuilder withClientKeyPassphrase(String clientKeyPassphrase);

87

88

// Timeout configuration

89

public ConfigBuilder withConnectionTimeout(int connectionTimeout);

90

public ConfigBuilder withRequestTimeout(int requestTimeout);

91

public ConfigBuilder withUploadRequestTimeout(int uploadRequestTimeout);

92

public ConfigBuilder withWatchReconnectInterval(int watchReconnectInterval);

93

public ConfigBuilder withWatchReconnectLimit(int watchReconnectLimit);

94

public ConfigBuilder withWebsocketPingInterval(long websocketPingInterval);

95

96

// Security configuration

97

public ConfigBuilder withTrustCerts(Boolean trustCerts);

98

public ConfigBuilder withDisableHostnameVerification(Boolean disableHostnameVerification);

99

100

// HTTP proxy configuration

101

public ConfigBuilder withHttpProxy(String httpProxy);

102

public ConfigBuilder withHttpsProxy(String httpsProxy);

103

public ConfigBuilder withNoProxy(String[] noProxy);

104

public ConfigBuilder withProxyUsername(String proxyUsername);

105

public ConfigBuilder withProxyPassword(String proxyPassword);

106

107

// Build the configuration

108

public Config build();

109

}

110

```

111

112

## Client Builder

113

114

### KubernetesClientBuilder Class

115

116

```java { .api }

117

public class KubernetesClientBuilder {

118

public KubernetesClientBuilder withConfig(Config config);

119

public KubernetesClientBuilder withConfig(String config);

120

public KubernetesClientBuilder withConfig(InputStream config);

121

public KubernetesClientBuilder withHttpClientFactory(HttpClient.Factory factory);

122

public KubernetesClientBuilder withTaskExecutor(Executor executor);

123

public KubernetesClientBuilder withTaskExecutorSupplier(ExecutorSupplier executorSupplier);

124

public KubernetesClientBuilder withHttpClientBuilderConsumer(Consumer<HttpClient.Builder> consumer);

125

public KubernetesClientBuilder withKubernetesSerialization(KubernetesSerialization kubernetesSerialization);

126

public KubernetesClient build();

127

}

128

```

129

130

## Usage Examples

131

132

### Auto-Configuration

133

134

The simplest way to create a client using auto-discovered configuration:

135

136

```java

137

try (KubernetesClient client = new KubernetesClientBuilder().build()) {

138

// Client automatically discovers configuration from:

139

// 1. System properties

140

// 2. Environment variables

141

// 3. ~/.kube/config file

142

// 4. Service account token (when running in cluster)

143

144

String namespace = client.getConfiguration().getNamespace();

145

System.out.println("Connected to cluster, default namespace: " + namespace);

146

}

147

```

148

149

### Custom Configuration

150

151

Creating a client with explicit configuration:

152

153

```java

154

Config config = new ConfigBuilder()

155

.withMasterUrl("https://kubernetes.example.com:6443")

156

.withNamespace("my-namespace")

157

.withOauthToken("my-token")

158

.withTrustCerts(true)

159

.withConnectionTimeout(10000)

160

.withRequestTimeout(30000)

161

.build();

162

163

try (KubernetesClient client = new KubernetesClientBuilder()

164

.withConfig(config)

165

.build()) {

166

167

// Use the client with custom configuration

168

PodList pods = client.pods().list();

169

}

170

```

171

172

### Configuration from Kubeconfig

173

174

Loading configuration from a specific kubeconfig file:

175

176

```java

177

Config config = Config.fromKubeconfig("/path/to/kubeconfig");

178

179

try (KubernetesClient client = new KubernetesClientBuilder()

180

.withConfig(config)

181

.build()) {

182

183

// Client uses the specified kubeconfig

184

NodeList nodes = client.nodes().list();

185

}

186

```

187

188

### Certificate-Based Authentication

189

190

Configuring client certificate authentication:

191

192

```java

193

Config config = new ConfigBuilder()

194

.withMasterUrl("https://kubernetes.example.com:6443")

195

.withCaCertFile("/path/to/ca.crt")

196

.withClientCertFile("/path/to/client.crt")

197

.withClientKeyFile("/path/to/client.key")

198

.withClientKeyPassphrase("key-passphrase")

199

.build();

200

201

try (KubernetesClient client = new KubernetesClientBuilder()

202

.withConfig(config)

203

.build()) {

204

205

// Client uses certificate authentication

206

ServiceList services = client.services().list();

207

}

208

```

209

210

### Proxy Configuration

211

212

Configuring HTTP proxy settings:

213

214

```java

215

Config config = new ConfigBuilder()

216

.withMasterUrl("https://kubernetes.example.com:6443")

217

.withHttpProxy("http://proxy.example.com:8080")

218

.withHttpsProxy("https://proxy.example.com:8080")

219

.withNoProxy(new String[]{"localhost", "127.0.0.1", "*.local"})

220

.withProxyUsername("proxy-user")

221

.withProxyPassword("proxy-password")

222

.build();

223

224

try (KubernetesClient client = new KubernetesClientBuilder()

225

.withConfig(config)

226

.build()) {

227

228

// Client uses proxy settings

229

NamespaceList namespaces = client.namespaces().list();

230

}

231

```

232

233

### Timeout Configuration

234

235

Configuring various timeout settings:

236

237

```java

238

Config config = new ConfigBuilder()

239

.withConnectionTimeout(15000) // 15 seconds to establish connection

240

.withRequestTimeout(60000) // 60 seconds for regular requests

241

.withUploadRequestTimeout(300000) // 5 minutes for upload requests

242

.withWatchReconnectInterval(1000) // 1 second between watch reconnect attempts

243

.withWatchReconnectLimit(10) // Maximum 10 reconnect attempts

244

.withWebsocketPingInterval(30000) // 30 seconds between websocket pings

245

.build();

246

247

try (KubernetesClient client = new KubernetesClientBuilder()

248

.withConfig(config)

249

.build()) {

250

251

// Client uses custom timeout settings

252

ConfigMapList configMaps = client.configMaps().list();

253

}

254

```

255

256

## Configuration Sources

257

258

The client configuration is auto-discovered from multiple sources in the following order of precedence:

259

260

1. **System Properties**: Java system properties starting with `kubernetes.`

261

2. **Environment Variables**: Environment variables like `KUBERNETES_MASTER`, `KUBERNETES_NAMESPACE`, etc.

262

3. **Kubeconfig File**: Default location `~/.kube/config` or specified by `KUBECONFIG` environment variable

263

4. **Service Account**: When running inside a Kubernetes pod, uses the mounted service account token

264

265

### Environment Variables

266

267

Common environment variables for configuration:

268

269

- `KUBERNETES_MASTER` - Kubernetes API server URL

270

- `KUBERNETES_NAMESPACE` - Default namespace

271

- `KUBERNETES_AUTH_TOKEN` - Authentication token

272

- `KUBERNETES_CA_CERTIFICATE_FILE` - CA certificate file path

273

- `KUBERNETES_CLIENT_CERTIFICATE_FILE` - Client certificate file path

274

- `KUBERNETES_CLIENT_KEY_FILE` - Client key file path

275

- `KUBERNETES_TRUST_CERTIFICATES` - Trust all certificates (true/false)

276

- `KUBERNETES_DISABLE_HOSTNAME_VERIFICATION` - Disable hostname verification (true/false)

277

278

### System Properties

279

280

Corresponding system properties use the `kubernetes.` prefix:

281

282

- `kubernetes.master` - Kubernetes API server URL

283

- `kubernetes.namespace` - Default namespace

284

- `kubernetes.auth.token` - Authentication token

285

- `kubernetes.certs.ca.file` - CA certificate file path

286

- `kubernetes.certs.client.file` - Client certificate file path

287

- `kubernetes.certs.client.key.file` - Client key file path

288

- `kubernetes.trust.certificates` - Trust all certificates

289

- `kubernetes.disable.hostname.verification` - Disable hostname verification