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

api-groups.mddocs/

0

# API Groups

1

2

The Fabric8 Kubernetes Client provides dedicated DSL interfaces for each Kubernetes API group, enabling type-safe access to specialized resources like Deployments, Jobs, Network Policies, and more. Each API group interface follows consistent patterns while providing resource-specific operations.

3

4

## Apps API Group

5

6

The Apps API group contains workload resources for running applications.

7

8

```java { .api }

9

public interface AppsAPIGroupDSL {

10

MixedOperation<Deployment, DeploymentList, RollableScalableResource<Deployment>> deployments();

11

MixedOperation<StatefulSet, StatefulSetList, RollableScalableResource<StatefulSet>> statefulSets();

12

MixedOperation<DaemonSet, DaemonSetList, Resource<DaemonSet>> daemonSets();

13

MixedOperation<ReplicaSet, ReplicaSetList, RollableScalableResource<ReplicaSet>> replicaSets();

14

MixedOperation<ControllerRevision, ControllerRevisionList, Resource<ControllerRevision>> controllerRevisions();

15

}

16

17

// Access via client

18

public interface KubernetesClient {

19

AppsAPIGroupDSL apps();

20

}

21

```

22

23

### Deployment Operations

24

25

```java

26

// Create a deployment

27

Deployment deployment = client.apps().deployments().create(new DeploymentBuilder()

28

.withNewMetadata()

29

.withName("nginx-deployment")

30

.withLabels(Map.of("app", "nginx"))

31

.endMetadata()

32

.withNewSpec()

33

.withReplicas(3)

34

.withNewSelector()

35

.addToMatchLabels("app", "nginx")

36

.endSelector()

37

.withNewTemplate()

38

.withNewMetadata()

39

.addToLabels("app", "nginx")

40

.endMetadata()

41

.withNewSpec()

42

.addNewContainer()

43

.withName("nginx")

44

.withImage("nginx:1.21")

45

.addNewPort()

46

.withContainerPort(80)

47

.endPort()

48

.endContainer()

49

.endSpec()

50

.endTemplate()

51

.endSpec()

52

.build());

53

54

// Scale deployment

55

client.apps().deployments().withName("nginx-deployment").scale(5);

56

57

// Rolling update

58

client.apps().deployments().withName("nginx-deployment").rolling()

59

.withTimeout(5, TimeUnit.MINUTES)

60

.updateImage("nginx:1.22");

61

62

// Check rollout status

63

client.apps().deployments().withName("nginx-deployment").isReady();

64

```

65

66

### StatefulSet Operations

67

68

```java

69

// Create a StatefulSet

70

StatefulSet statefulSet = client.apps().statefulSets().create(new StatefulSetBuilder()

71

.withNewMetadata()

72

.withName("web-statefulset")

73

.endMetadata()

74

.withNewSpec()

75

.withReplicas(3)

76

.withServiceName("nginx-service")

77

.withNewSelector()

78

.addToMatchLabels("app", "nginx")

79

.endSelector()

80

.withNewTemplate()

81

.withNewMetadata()

82

.addToLabels("app", "nginx")

83

.endMetadata()

84

.withNewSpec()

85

.addNewContainer()

86

.withName("nginx")

87

.withImage("nginx:1.21")

88

.endContainer()

89

.endSpec()

90

.endTemplate()

91

.addNewVolumeClaimTemplate()

92

.withNewMetadata()

93

.withName("web-storage")

94

.endMetadata()

95

.withNewSpec()

96

.withAccessModes("ReadWriteOnce")

97

.withNewResources()

98

.addToRequests("storage", new Quantity("1Gi"))

99

.endResources()

100

.endSpec()

101

.endVolumeClaimTemplate()

102

.endSpec()

103

.build());

104

```

105

106

## Batch API Group

107

108

The Batch API group contains resources for running batch workloads.

109

110

```java { .api }

111

public interface BatchAPIGroupDSL {

112

// V1 API

113

V1BatchAPIGroupDSL v1();

114

115

// Default methods (v1)

116

MixedOperation<Job, JobList, ScalableResource<Job>> jobs();

117

MixedOperation<CronJob, CronJobList, Resource<CronJob>> cronjobs();

118

}

119

120

public interface V1BatchAPIGroupDSL {

121

MixedOperation<Job, JobList, ScalableResource<Job>> jobs();

122

MixedOperation<CronJob, CronJobList, Resource<CronJob>> cronjobs();

123

}

124

125

// Access via client

126

public interface KubernetesClient {

127

BatchAPIGroupDSL batch();

128

}

129

```

130

131

### Job Operations

132

133

```java

134

// Create a job

135

Job job = client.batch().jobs().create(new JobBuilder()

136

.withNewMetadata()

137

.withName("batch-job")

138

.endMetadata()

139

.withNewSpec()

140

.withCompletions(1)

141

.withParallelism(1)

142

.withNewTemplate()

143

.withNewSpec()

144

.addNewContainer()

145

.withName("worker")

146

.withImage("busybox:1.35")

147

.withCommand("sh", "-c", "echo 'Processing batch job'; sleep 30")

148

.endContainer()

149

.withRestartPolicy("Never")

150

.endSpec()

151

.endTemplate()

152

.endSpec()

153

.build());

154

155

// Wait for job completion

156

Job completedJob = client.batch().jobs().withName("batch-job")

157

.waitUntilCondition(job -> {

158

JobStatus status = job.getStatus();

159

return status != null && status.getSucceeded() != null && status.getSucceeded() > 0;

160

}, 5, TimeUnit.MINUTES);

161

```

162

163

### CronJob Operations

164

165

```java

166

// Create a CronJob

167

CronJob cronJob = client.batch().cronjobs().create(new CronJobBuilder()

168

.withNewMetadata()

169

.withName("scheduled-job")

170

.endMetadata()

171

.withNewSpec()

172

.withSchedule("0 2 * * *") // Run daily at 2 AM

173

.withNewJobTemplate()

174

.withNewSpec()

175

.withNewTemplate()

176

.withNewSpec()

177

.addNewContainer()

178

.withName("backup")

179

.withImage("postgres:13")

180

.withCommand("pg_dump", "-h", "database", "mydb")

181

.endContainer()

182

.withRestartPolicy("OnFailure")

183

.endSpec()

184

.endTemplate()

185

.endSpec()

186

.endJobTemplate()

187

.endSpec()

188

.build());

189

```

190

191

## Networking API Group

192

193

The Network API group contains networking-related resources.

194

195

```java { .api }

196

public interface NetworkAPIGroupDSL {

197

// V1 API

198

V1NetworkAPIGroupDSL v1();

199

200

// Default methods (v1)

201

MixedOperation<NetworkPolicy, NetworkPolicyList, Resource<NetworkPolicy>> networkPolicies();

202

MixedOperation<Ingress, IngressList, Resource<Ingress>> ingresses();

203

MixedOperation<IngressClass, IngressClassList, Resource<IngressClass>> ingressClasses();

204

}

205

206

// Access via client

207

public interface KubernetesClient {

208

NetworkAPIGroupDSL network();

209

}

210

```

211

212

### Network Policy Operations

213

214

```java

215

// Create a network policy

216

NetworkPolicy policy = client.network().networkPolicies().create(new NetworkPolicyBuilder()

217

.withNewMetadata()

218

.withName("deny-all")

219

.withNamespace("production")

220

.endMetadata()

221

.withNewSpec()

222

.withNewPodSelector() // Empty selector = all pods

223

.endPodSelector()

224

.withPolicyTypes("Ingress", "Egress")

225

// No ingress/egress rules = deny all

226

.endSpec()

227

.build());

228

229

// Allow specific ingress traffic

230

NetworkPolicy allowWeb = client.network().networkPolicies().create(new NetworkPolicyBuilder()

231

.withNewMetadata()

232

.withName("allow-web-traffic")

233

.endMetadata()

234

.withNewSpec()

235

.withNewPodSelector()

236

.addToMatchLabels("app", "web")

237

.endPodSelector()

238

.withPolicyTypes("Ingress")

239

.addNewIngress()

240

.addNewPort()

241

.withPort(new IntOrString(80))

242

.withProtocol("TCP")

243

.endPort()

244

.addNewFrom()

245

.withNewPodSelector()

246

.addToMatchLabels("role", "frontend")

247

.endPodSelector()

248

.endFrom()

249

.endIngress()

250

.endSpec()

251

.build());

252

```

253

254

### Ingress Operations

255

256

```java

257

// Create an ingress

258

Ingress ingress = client.network().ingresses().create(new IngressBuilder()

259

.withNewMetadata()

260

.withName("web-ingress")

261

.withAnnotations(Map.of(

262

"nginx.ingress.kubernetes.io/rewrite-target", "/",

263

"cert-manager.io/cluster-issuer", "letsencrypt-prod"

264

))

265

.endMetadata()

266

.withNewSpec()

267

.addNewTl()

268

.withHosts("example.com")

269

.withSecretName("example-tls")

270

.endTl()

271

.addNewRule()

272

.withHost("example.com")

273

.withNewHttp()

274

.addNewPath()

275

.withPath("/")

276

.withPathType("Prefix")

277

.withNewBackend()

278

.withNewService()

279

.withName("web-service")

280

.withNewPort()

281

.withNumber(80)

282

.endPort()

283

.endService()

284

.endBackend()

285

.endPath()

286

.endHttp()

287

.endRule()

288

.endSpec()

289

.build());

290

```

291

292

## RBAC API Group

293

294

Role-Based Access Control resources for security and authorization.

295

296

```java { .api }

297

public interface RbacAPIGroupDSL {

298

// V1 API

299

V1RbacAPIGroupDSL v1();

300

301

// Default methods (v1)

302

MixedOperation<Role, RoleList, Resource<Role>> roles();

303

MixedOperation<RoleBinding, RoleBindingList, Resource<RoleBinding>> roleBindings();

304

NonNamespaceOperation<ClusterRole, ClusterRoleList, Resource<ClusterRole>> clusterRoles();

305

NonNamespaceOperation<ClusterRoleBinding, ClusterRoleBindingList, Resource<ClusterRoleBinding>> clusterRoleBindings();

306

}

307

308

// Access via client

309

public interface KubernetesClient {

310

RbacAPIGroupDSL rbac();

311

}

312

```

313

314

### RBAC Operations

315

316

```java

317

// Create a Role

318

Role role = client.rbac().roles().create(new RoleBuilder()

319

.withNewMetadata()

320

.withName("pod-reader")

321

.withNamespace("development")

322

.endMetadata()

323

.addNewRule()

324

.withApiGroups("")

325

.withResources("pods")

326

.withVerbs("get", "list", "watch")

327

.endRule()

328

.build());

329

330

// Create a RoleBinding

331

RoleBinding roleBinding = client.rbac().roleBindings().create(new RoleBindingBuilder()

332

.withNewMetadata()

333

.withName("read-pods")

334

.withNamespace("development")

335

.endMetadata()

336

.addNewSubject()

337

.withKind("User")

338

.withName("jane@example.com")

339

.withApiGroup("rbac.authorization.k8s.io")

340

.endSubject()

341

.withNewRoleRef()

342

.withKind("Role")

343

.withName("pod-reader")

344

.withApiGroup("rbac.authorization.k8s.io")

345

.endRoleRef()

346

.build());

347

348

// Create a ClusterRole

349

ClusterRole clusterRole = client.rbac().clusterRoles().create(new ClusterRoleBuilder()

350

.withNewMetadata()

351

.withName("cluster-reader")

352

.endMetadata()

353

.addNewRule()

354

.withApiGroups("")

355

.withResources("nodes", "namespaces")

356

.withVerbs("get", "list")

357

.endRule()

358

.build());

359

```

360

361

## Storage API Group

362

363

Storage-related resources for persistent storage management.

364

365

```java { .api }

366

public interface StorageAPIGroupDSL {

367

// V1 API

368

V1StorageAPIGroupDSL v1();

369

370

// Default methods (v1)

371

NonNamespaceOperation<StorageClass, StorageClassList, Resource<StorageClass>> storageClasses();

372

NonNamespaceOperation<VolumeAttachment, VolumeAttachmentList, Resource<VolumeAttachment>> volumeAttachments();

373

NonNamespaceOperation<CSIDriver, CSIDriverList, Resource<CSIDriver>> csiDrivers();

374

NonNamespaceOperation<CSINode, CSINodeList, Resource<CSINode>> csiNodes();

375

}

376

377

// Access via client

378

public interface KubernetesClient {

379

StorageAPIGroupDSL storage();

380

}

381

```

382

383

### Storage Class Operations

384

385

```java

386

// Create a StorageClass

387

StorageClass storageClass = client.storage().storageClasses().create(new StorageClassBuilder()

388

.withNewMetadata()

389

.withName("fast-ssd")

390

.endMetadata()

391

.withProvisioner("kubernetes.io/aws-ebs")

392

.withParameters(Map.of(

393

"type", "gp3",

394

"iops", "3000",

395

"throughput", "125"

396

))

397

.withReclaimPolicy("Delete")

398

.withVolumeBindingMode("WaitForFirstConsumer")

399

.withAllowVolumeExpansion(true)

400

.build());

401

```

402

403

## Autoscaling API Group

404

405

Horizontal Pod Autoscaler resources for automatic scaling.

406

407

```java { .api }

408

public interface AutoscalingAPIGroupDSL {

409

// V1 API

410

V1AutoscalingAPIGroupDSL v1();

411

412

// V2 API

413

V2AutoscalingAPIGroupDSL v2();

414

415

// Default methods (v2)

416

MixedOperation<HorizontalPodAutoscaler, HorizontalPodAutoscalerList, Resource<HorizontalPodAutoscaler>> horizontalPodAutoscalers();

417

}

418

419

// Access via client

420

public interface KubernetesClient {

421

AutoscalingAPIGroupDSL autoscaling();

422

}

423

```

424

425

### HPA Operations

426

427

```java

428

// Create an HPA (v2)

429

HorizontalPodAutoscaler hpa = client.autoscaling().v2().horizontalPodAutoscalers().create(

430

new HorizontalPodAutoscalerBuilder()

431

.withNewMetadata()

432

.withName("web-app-hpa")

433

.endMetadata()

434

.withNewSpec()

435

.withNewScaleTargetRef()

436

.withApiVersion("apps/v1")

437

.withKind("Deployment")

438

.withName("web-app")

439

.endScaleTargetRef()

440

.withMinReplicas(2)

441

.withMaxReplicas(10)

442

.addNewMetric()

443

.withType("Resource")

444

.withNewResource()

445

.withName("cpu")

446

.withNewTarget()

447

.withType("Utilization")

448

.withAverageUtilization(70)

449

.endTarget()

450

.endResource()

451

.endMetric()

452

.endSpec()

453

.build());

454

```

455

456

## Additional API Groups

457

458

The client provides access to many other API groups:

459

460

- **ApiextensionsAPIGroupDSL** - Custom Resource Definitions

461

- **CertificatesAPIGroupDSL** - Certificate Signing Requests

462

- **DiscoveryAPIGroupDSL** - API discovery and endpoint slices

463

- **EventingAPIGroupDSL** - Event resources (events.k8s.io)

464

- **FlowControlAPIGroupDSL** - API priority and fairness

465

- **MetricAPIGroupDSL** - Metrics API access

466

- **PolicyAPIGroupDSL** - Pod Security and Pod Disruption Budgets

467

- **SchedulingAPIGroupDSL** - Priority Classes

468

469

Each follows similar patterns with versioned sub-interfaces and consistent operation methods.