Kubernetes Programming With Go: Programming Kubernetes Clients and Operators Using Go and The Kubernetes API 1st Edition Philippe Martin

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

Kubernetes Programming with Go:

Programming Kubernetes Clients and


Operators Using Go and the
Kubernetes API 1st Edition Philippe
Martin
Visit to download the full and correct content document:
https://ebookmass.com/product/kubernetes-programming-with-go-programming-kuber
netes-clients-and-operators-using-go-and-the-kubernetes-api-1st-edition-philippe-mar
tin/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Kubernetes Programming with Go: Programming Kubernetes


Clients and Operators Using Go and the Kubernetes API
1st Edition Philippe Martin

https://ebookmass.com/product/kubernetes-programming-with-go-
programming-kubernetes-clients-and-operators-using-go-and-the-
kubernetes-api-1st-edition-philippe-martin-2/

Ansible for Kubernetes by Example: Automate Your


Kubernetes Cluster with Ansible 1st Edition Luca Berton

https://ebookmass.com/product/ansible-for-kubernetes-by-example-
automate-your-kubernetes-cluster-with-ansible-1st-edition-luca-
berton-2/

Ansible for Kubernetes by Example: Automate Your


Kubernetes Cluster with Ansible 1st Edition Luca Berton

https://ebookmass.com/product/ansible-for-kubernetes-by-example-
automate-your-kubernetes-cluster-with-ansible-1st-edition-luca-
berton/

Software Development with Go: Cloud-Native Programming


using Golang with Linux and Docker 1st Edition Nanik
Tolaram

https://ebookmass.com/product/software-development-with-go-cloud-
native-programming-using-golang-with-linux-and-docker-1st-
edition-nanik-tolaram/
Deploy Container Applications Using Kubernetes:
Implementations with microk8s and AWS EKS Shiva
Subramanian

https://ebookmass.com/product/deploy-container-applications-
using-kubernetes-implementations-with-microk8s-and-aws-eks-shiva-
subramanian/

Kubernetes Secrets Handbook Emmanouil Gkatziouras

https://ebookmass.com/product/kubernetes-secrets-handbook-
emmanouil-gkatziouras/

The Kubernetes Book: 2024 Edition Nigel Poulton

https://ebookmass.com/product/the-kubernetes-book-2024-edition-
nigel-poulton/

Observability with Grafana: Monitor, control, and


visualize your Kubernetes and cloud platforms using the
LGTM stack Rob Chapman

https://ebookmass.com/product/observability-with-grafana-monitor-
control-and-visualize-your-kubernetes-and-cloud-platforms-using-
the-lgtm-stack-rob-chapman/

Beginning Cloud Native Development with MicroProfile,


Jakarta EE, and Kubernetes 1st Edition Tarun Telang

https://ebookmass.com/product/beginning-cloud-native-development-
with-microprofile-jakarta-ee-and-kubernetes-1st-edition-tarun-
telang/
Kubernetes
Programming
with Go
Programming Kubernetes Clients
and Operators Using Go and
the Kubernetes API

Philippe Martin
Kubernetes Programming
with Go
Programming Kubernetes Clients
and Operators Using
Go and the Kubernetes API

Philippe Martin
Kubernetes Programming with Go: Programming Kubernetes Clients and Operators
Using Go and the Kubernetes API

Philippe Martin
Blanquefort, France

ISBN-13 (pbk): 978-1-4842-9025-5 ISBN-13 (electronic): 978-1-4842-9026-2


https://doi.org/10.1007/978-1-4842-9026-2

Copyright © 2023 by Philippe Martin


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Divya Modi
Development Editor: James Markham
Coordinating Editor: Divya Modi
Copy Editor: Kim Burton Wiseman
Cover designed by eStudioCalamar
Cover image designed by Freepik (www.freepik.com)
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 New York Plaza,
New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail [email protected], or
visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is
Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers
on GitHub via the book's product page, located at https://github.com/Apress/Kubernetes-Programming-
with-Go-by-Philippe-Martin. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
To Mélina and Elsa, my constant source of truth
Table of Contents
About the Author��������������������������������������������������������������������������������������������������� xiii

About the Technical Reviewers�������������������������������������������������������������������������������xv


Acknowledgments�������������������������������������������������������������������������������������������������xvii

Introduction������������������������������������������������������������������������������������������������������������xix

Chapter 1: Kubernetes API Introduction������������������������������������������������������������������� 1


Kubernetes Platform at a Glance�������������������������������������������������������������������������������������������������� 1
OpenAPI Specification������������������������������������������������������������������������������������������������������������������� 3
Verbs and Kinds���������������������������������������������������������������������������������������������������������������������������� 5
Group-Version-Resource��������������������������������������������������������������������������������������������������������������� 6
Sub-resources������������������������������������������������������������������������������������������������������������������������������ 8
Official API Reference Documentation������������������������������������������������������������������������������������������ 9
The Deployment Documentation������������������������������������������������������������������������������������������� 10
Operations Documentation���������������������������������������������������������������������������������������������������� 12
The Pod Documentation�������������������������������������������������������������������������������������������������������� 14
One-Page Version of the Documentation������������������������������������������������������������������������������� 15
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 16

Chapter 2: Kubernetes API Operations������������������������������������������������������������������� 17


Examining Requests������������������������������������������������������������������������������������������������������������������� 17
Making Requests������������������������������������������������������������������������������������������������������������������������ 18
Using kubectl as a Proxy������������������������������������������������������������������������������������������������������� 18
Creating a Resource�������������������������������������������������������������������������������������������������������������� 19
Getting Information About a Resource����������������������������������������������������������������������������������� 20
Getting the List of Resources������������������������������������������������������������������������������������������������ 20

v
Table of Contents

Filtering the Result of a List�������������������������������������������������������������������������������������������������� 21


Deleting a Resource�������������������������������������������������������������������������������������������������������������� 26
Deleting a Collection of Resources���������������������������������������������������������������������������������������� 26
Updating a Resource������������������������������������������������������������������������������������������������������������� 27
Managing Conflicts When Updating a Resource�������������������������������������������������������������������� 28
Using a Strategic Merge Patch to Update a Resource����������������������������������������������������������� 32
Applying Resources Server-side�������������������������������������������������������������������������������������������� 38
Watching Resources�������������������������������������������������������������������������������������������������������������� 44
Filtering During a Watch Session������������������������������������������������������������������������������������������� 45
Watching After Listing Resources������������������������������������������������������������������������������������������ 45
Restarting a watch Request�������������������������������������������������������������������������������������������������� 46
Allowing Bookmarks to Efficiently Restart a watch Request������������������������������������������������� 47
Paginating Results����������������������������������������������������������������������������������������������������������������� 50
Getting Results in Various Formats��������������������������������������������������������������������������������������������� 52
Getting Results as a Table����������������������������������������������������������������������������������������������������� 52
Using the YAML Format��������������������������������������������������������������������������������������������������������� 54
Using the Protobuf Format���������������������������������������������������������������������������������������������������� 54
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 55

Chapter 3: Working with API Resources in Go�������������������������������������������������������� 57


API Library Sources and Import�������������������������������������������������������������������������������������������������� 57
Content of a Package������������������������������������������������������������������������������������������������������������������ 58
types.go��������������������������������������������������������������������������������������������������������������������������������� 58
register.go������������������������������������������������������������������������������������������������������������������������������ 59
doc.go������������������������������������������������������������������������������������������������������������������������������������ 60
generated.pb.go and generated.proto����������������������������������������������������������������������������������� 60
types_swagger_doc_generated.go��������������������������������������������������������������������������������������� 60
zz_generated.deepcopy.go���������������������������������������������������������������������������������������������������� 61
Specific Content in core/v1��������������������������������������������������������������������������������������������������������� 61
ObjectReference�������������������������������������������������������������������������������������������������������������������� 61
ResourceList�������������������������������������������������������������������������������������������������������������������������� 62
Taint��������������������������������������������������������������������������������������������������������������������������������������� 64

vi
Table of Contents

Toleration������������������������������������������������������������������������������������������������������������������������������� 65
Well-Known Labels���������������������������������������������������������������������������������������������������������������� 66
Writing Kubernetes Resources in Go������������������������������������������������������������������������������������������ 67
Importing the Package���������������������������������������������������������������������������������������������������������� 67
The TypeMeta Fields�������������������������������������������������������������������������������������������������������������� 68
The ObjectMeta Fields����������������������������������������������������������������������������������������������������������� 69
Spec and Status�������������������������������������������������������������������������������������������������������������������� 76
Comparison with Writing YAML Manifests����������������������������������������������������������������������������� 76
A Complete Example������������������������������������������������������������������������������������������������������������������� 78
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 83

Chapter 4: Using Common Types���������������������������������������������������������������������������� 85


Pointers��������������������������������������������������������������������������������������������������������������������������������������� 85
Getting the Reference of a Value������������������������������������������������������������������������������������������� 85
Dereferencing a Pointer��������������������������������������������������������������������������������������������������������� 86
Comparing Two Referenced Values��������������������������������������������������������������������������������������� 86
Quantities������������������������������������������������������������������������������������������������������������������������������������ 87
Parsing a String as Quantity�������������������������������������������������������������������������������������������������� 87
Using an inf.Dec as a Quantity����������������������������������������������������������������������������������������������� 88
Using a Scaled Integer as a Quantity������������������������������������������������������������������������������������� 89
Operations on Quantities������������������������������������������������������������������������������������������������������� 90
IntOrString����������������������������������������������������������������������������������������������������������������������������������� 90
Time�������������������������������������������������������������������������������������������������������������������������������������������� 92
Factory Methods�������������������������������������������������������������������������������������������������������������������� 92
Operations on Time���������������������������������������������������������������������������������������������������������������� 92
Conclusion���������������������������������������������������������������������������������������������������������������������������������� 93

Chapter 5: The API Machinery�������������������������������������������������������������������������������� 95


The Schema Package����������������������������������������������������������������������������������������������������������������� 96
Scheme��������������������������������������������������������������������������������������������������������������������������������������� 97
Initialization��������������������������������������������������������������������������������������������������������������������������� 98
Mapping������������������������������������������������������������������������������������������������������������������������������� 100

vii
Table of Contents

Conversion��������������������������������������������������������������������������������������������������������������������������� 101
Serialization������������������������������������������������������������������������������������������������������������������������� 103
RESTMapper����������������������������������������������������������������������������������������������������������������������������� 105
Kind to Resource����������������������������������������������������������������������������������������������������������������� 106
Resource to Kind����������������������������������������������������������������������������������������������������������������� 107
Finding Resources��������������������������������������������������������������������������������������������������������������� 107
The DefaultRESTMapper Implementation���������������������������������������������������������������������������� 107
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 108

Chapter 6: The Client-go Library��������������������������������������������������������������������������� 109


Connecting to the Cluster��������������������������������������������������������������������������������������������������������� 110
In-cluster Configuration������������������������������������������������������������������������������������������������������� 110
Out-of-Cluster Configuration����������������������������������������������������������������������������������������������� 110
Getting a Clientset��������������������������������������������������������������������������������������������������������������������� 115
Using the Clientset�������������������������������������������������������������������������������������������������������������������� 116
Examining the Requests����������������������������������������������������������������������������������������������������������� 119
Creating a Resource������������������������������������������������������������������������������������������������������������������ 120
Getting Information About a Resource�������������������������������������������������������������������������������������� 122
Getting List of Resources���������������������������������������������������������������������������������������������������������� 123
Filtering the Result of a List������������������������������������������������������������������������������������������������������ 125
Setting LabelSelector Using the Labels Package���������������������������������������������������������������� 125
Setting Fieldselector Using the Fields Package������������������������������������������������������������������ 128
Deleting a Resource������������������������������������������������������������������������������������������������������������������ 130
Deleting a Collection of Resources������������������������������������������������������������������������������������������� 133
Updating a Resource����������������������������������������������������������������������������������������������������������������� 134
Using a Strategic Merge Patch to Update a Resource�������������������������������������������������������������� 135
Applying Resources Server-side with Patch����������������������������������������������������������������������������� 138
Server-side Apply Using Apply Configurations�������������������������������������������������������������������������� 140
Building an ApplyConfiguration from Scratch���������������������������������������������������������������������� 142
Building an ApplyConfiguration from an Existing Resource������������������������������������������������ 143

viii
Table of Contents

Watching Resources����������������������������������������������������������������������������������������������������������������� 145


Errors and Statuses������������������������������������������������������������������������������������������������������������������ 149
Definition of the metav1.Status Structure��������������������������������������������������������������������������� 149
Error Returned by Clientset Operations������������������������������������������������������������������������������� 153
RESTClient�������������������������������������������������������������������������������������������������������������������������������� 154
Building the Request����������������������������������������������������������������������������������������������������������� 154
Executing the Request��������������������������������������������������������������������������������������������������������� 161
Exploiting the Result������������������������������������������������������������������������������������������������������������ 161
Getting Result as a Table����������������������������������������������������������������������������������������������������������� 162
Discovery Client������������������������������������������������������������������������������������������������������������������������ 164
RESTMapper����������������������������������������������������������������������������������������������������������������������������� 165
PriorityRESTMapper������������������������������������������������������������������������������������������������������������ 165
DeferredDiscoveryRESTMapper������������������������������������������������������������������������������������������ 167
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 167

Chapter 7: Testing Applications Using Client-go�������������������������������������������������� 169


Fake Clientset��������������������������������������������������������������������������������������������������������������������������� 170
Checking the Result of the Function������������������������������������������������������������������������������������ 171
Reacting to Actions�������������������������������������������������������������������������������������������������������������� 173
Checking the Actions����������������������������������������������������������������������������������������������������������� 177
Fake REST Client����������������������������������������������������������������������������������������������������������������������� 185
FakeDiscovery Client���������������������������������������������������������������������������������������������������������������� 188
Stubbing the ServerVersion������������������������������������������������������������������������������������������������� 189
Actions��������������������������������������������������������������������������������������������������������������������������������� 190
Mocking Resources������������������������������������������������������������������������������������������������������������� 190
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 191

Chapter 8: Extending Kubernetes API with Custom Resources Definitions���������� 193


Performing Operations in Go����������������������������������������������������������������������������������������������������� 194
The CustomResourceDefinition in Detail����������������������������������������������������������������������������������� 195
Naming the Resource���������������������������������������������������������������������������������������������������������� 196
Definition of the Resource Versions������������������������������������������������������������������������������������� 197
Converting Between Versions���������������������������������������������������������������������������������������������� 198
ix
Table of Contents

Schema of the Resource����������������������������������������������������������������������������������������������������������� 199


Deploying a Custom Resource Definition���������������������������������������������������������������������������������� 201
Additional Printer Columns������������������������������������������������������������������������������������������������������� 204
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 207

Chapter 9: Working with Custom Resources�������������������������������������������������������� 209


Generating a Clientset��������������������������������������������������������������������������������������������������������������� 209
Using deepcopy-gen������������������������������������������������������������������������������������������������������������ 211
Using client-gen������������������������������������������������������������������������������������������������������������������ 213
Using the Generated Clientset��������������������������������������������������������������������������������������������� 216
Using the Generated fake Clientset������������������������������������������������������������������������������������� 217
Using the Unstructured Package and Dynamic Client��������������������������������������������������������������� 217
The Unstructured Type��������������������������������������������������������������������������������������������������������� 217
The UnstructuredList Type��������������������������������������������������������������������������������������������������� 221
Converting Between Typed and Unstructured Objects�������������������������������������������������������� 223
The Dynamic Client�������������������������������������������������������������������������������������������������������������� 223
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 229

Chapter 10: Writing Operators withthe Controller-­Runtime Library��������������������� 231


The Manager����������������������������������������������������������������������������������������������������������������������������� 232
The Controller��������������������������������������������������������������������������������������������������������������������������� 235
Creating a Controller����������������������������������������������������������������������������������������������������������� 236
Watching Resources������������������������������������������������������������������������������������������������������������ 237
A First Example������������������������������������������������������������������������������������������������������������������� 241
Using the Controller Builder������������������������������������������������������������������������������������������������ 244
A Second Example Using the ControllerBuilder������������������������������������������������������������������� 245
Injecting Manager Resources into the Reconciler��������������������������������������������������������������� 247
Using the Client������������������������������������������������������������������������������������������������������������������������� 250
Getting Information About a Resource��������������������������������������������������������������������������������� 250
Listing Resources���������������������������������������������������������������������������������������������������������������� 251
Creating a Resource������������������������������������������������������������������������������������������������������������ 254
Deleting a Resource������������������������������������������������������������������������������������������������������������ 254

x
Table of Contents

Deleting a Collection of Resources�������������������������������������������������������������������������������������� 255


Updating a Resource����������������������������������������������������������������������������������������������������������� 256
Patching a Resource������������������������������������������������������������������������������������������������������������ 256
Updating the Status of a Resource�������������������������������������������������������������������������������������� 259
Patching the Status of a Resource�������������������������������������������������������������������������������������� 260
Logging������������������������������������������������������������������������������������������������������������������������������������� 261
Verbosity������������������������������������������������������������������������������������������������������������������������������ 262
Predefined Values���������������������������������������������������������������������������������������������������������������� 262
Logger Name����������������������������������������������������������������������������������������������������������������������� 262
Getting the Logger from Context����������������������������������������������������������������������������������������� 263
Events��������������������������������������������������������������������������������������������������������������������������������������� 263
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 265

Chapter 11: Writing the Reconcile Loop��������������������������������������������������������������� 267


Writing the Reconcile Function������������������������������������������������������������������������������������������������� 268
Checking Whether the Resource Exists������������������������������������������������������������������������������� 268
Implementing the Reconciled Resource������������������������������������������������������������������������������ 268
Simple Implementation Example����������������������������������������������������������������������������������������� 270
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 275

Chapter 12: Testing the Reconcile Loop��������������������������������������������������������������� 277


The envtest Package����������������������������������������������������������������������������������������������������������������� 277
Installing envtest Binaries��������������������������������������������������������������������������������������������������� 277
Using envtest����������������������������������������������������������������������������������������������������������������������� 278
Defining a ginkgo Suite������������������������������������������������������������������������������������������������������������� 279
Writing the Tests����������������������������������������������������������������������������������������������������������������������� 283
Test 1����������������������������������������������������������������������������������������������������������������������������������� 284
Test 2����������������������������������������������������������������������������������������������������������������������������������� 285
Test 3����������������������������������������������������������������������������������������������������������������������������������� 285
Test 4����������������������������������������������������������������������������������������������������������������������������������� 285
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 290

xi
Table of Contents

Chapter 13: Creating an Operator with Kubebuilder�������������������������������������������� 291


Installing Kubebuilder��������������������������������������������������������������������������������������������������������������� 291
Creating a Project��������������������������������������������������������������������������������������������������������������������� 291
Adding a Custom Resource to the Project�������������������������������������������������������������������������������� 293
Building and Deploying Manifests�������������������������������������������������������������������������������������������� 295
Running the Manager Locally��������������������������������������������������������������������������������������������������� 295
Personalizing the Custom Resource����������������������������������������������������������������������������������������� 296
Editing the Go Structures���������������������������������������������������������������������������������������������������� 297
Enabling the Status Subresource���������������������������������������������������������������������������������������� 297
Defining Printer Columns����������������������������������������������������������������������������������������������������� 297
Regenerating the Files�������������������������������������������������������������������������������������������������������� 298
Implementing the Reconcile Function�������������������������������������������������������������������������������������� 299
Adding RBAC Annotations��������������������������������������������������������������������������������������������������������� 299
Deploying the Operator on the Cluster�������������������������������������������������������������������������������������� 300
Creating a New Version of the Resource����������������������������������������������������������������������������������� 301
Defining a New Version������������������������������������������������������������������������������������������������������� 302
Implementing Hub and Convertible������������������������������������������������������������������������������������� 303
Setting Up the webhook������������������������������������������������������������������������������������������������������ 305
Updating kustomization Files���������������������������������������������������������������������������������������������� 306
Using Various Versions�������������������������������������������������������������������������������������������������������� 306
Conclusion�������������������������������������������������������������������������������������������������������������������������������� 308

Index��������������������������������������������������������������������������������������������������������������������� 309

xii
About the Author
Philippe Martin has been working with Kubernetes for
five years, first by creating an Operator to deploy video
CDNs into the cloud, later helping companies deploy their
applications into Kubernetes, then writing a Client to help
developers work in a Kubernetes environment. Philippe
has passed the CKAD, CKA, and CKS certifications. He has
extensive experience with distributed systems and open-
source software: he started his career 20 years ago creating
thin clients based on the Linux kernel and open-­source
components. He is currently working at Red Hat on the
Development Tools team.
Philippe has been active in the development of Kubernetes, especially its
documentation, and participates in the translation of the official documentation into
French, has edited two reference books about the Kubernetes API and kubectl, and is
responsible for the French translation of the Kubernetes Dashboard. He participated in
Google Season of Docs to create the new Kubernetes API Reference section of the official
documentation and is maintaining it.

xiii
About the Technical Reviewers
Bartosz Majsak writes code for fun and profit while proudly
wearing a red fedora (also known as the Red Hat). He has
been long-time open-source contributor and Java developer
turned into Golang aficionado. Bartosz is overly enthusiastic
about coffee, open source, and speaking at conferences,
not necessarily in that order. One thing that perhaps proves
he is not a total geek is his addiction to alpine skiing (and
running).

Prasanth is a Blockchain Certified Professional, Professional


Scrum Master, and Microsoft Certified Trainer who is
passionate about helping others learn how to use and gain
benefits from the latest technologies. He is a thought leader
and practitioner in Blockchain, Cloud, and Scrum. He also
handles the Agile Methodology, Cloud, and Blockchain
technology community initiatives within TransUnion
through coaching, mentoring, and grooming techniques.
Prasanth is an adjunct professor and a technical speaker.
He was selected as a speaker at the China International
Industry Big Data Expo 2018 by the Chinese government and also was invited to the
International Blockchain Council by the Government of Telangana and Goa. In addition,
he received accolades from the Chinese government for his presentation at China
International Industry Big Data Expo 2018. Prasanth has published his Patent, entitled
“Digital Educational Certificate Management System Using IPFS-Based Blockchain.”
To date, he has interacted extensively, reaching more than 50,000 students,
mostly within the technical domain. Prasanth is a working group member of the
CryptoCurrency Certification Consortium, the Scrum Alliance, the Scrum Organization,
and the International Institute of Business Analysis.

xv
Acknowledgments
I would like to thank the whole Anevia “CDN” team who started working with me on
Kubernetes back in 2018: David, Ansou, Hossam, Yassine, Étienne, Jason, and Michaël.
Special thanks to Damien Lucas for initiating this project and for having trusted us with
this challenge.
My discovery of Kubernetes has been much easier and pleasant thanks to the TGIK
channel and its numerous episodes, hosted by Joe Beda, Kris Nova, and many others.
Plus, thanks to all the Kubernetes community for such a great ecosystem!

xvii
Introduction
Back in 2017, I was working for a company building video streaming software. At the end
of that year, a small team, including me, got assigned a new job to work on deploying
the Video CDN developed by the company on Kubernetes. We decided to explore the
concept of Custom Resources and Operators to deploy this CDN.
The current Kubernetes release was 1.9, the concept of Custom Resource Definition
had just been released in 1.7, and the sample-controller repository was the only
documentation we knew of to help build an Operator. The Kubernetes ecosystem,
being especially lively, had tools appearing in the following months, specifically the
Kubebuilder SDK. Thus, our project was launched.
From that moment on, I spent numerous days exploring how to build Operators and
other programs interacting with the Kubernetes API. But the damage was done: I had
started to learn Kubernetes programming from specific to general, and it took me a long
time to fully understand the innards of the Kubernetes API.
I have written this book in the hope that it can teach new Kubernetes developers how
to program, from general to specific, with the Kubernetes API in Go.

Chapters at a Glance
The target reader for this book has some experience working with REST APIs, accessing
them either by HTTP or using clients for specific languages; and has some knowledge of
the Kubernetes platform, essentially as a user—for example, some experience deploying
such APIs or frontend applications with the help of YAML manifests.

• Chapter 1 of the book explores the Kubernetes API and how it


implements the principles of REST. It especially focuses on the
Group-Version-Resource organization and the Kind concept
proposed by the API.
• Chapter 2 continues by covering the operations proposed by the API
and the details of each operation, using the HTTP protocol.

xix
Introduction

• Chapters 3 to 5 describe the common and “low-level” Go libraries to


work with the Kubernetes API: the API and API Machinery Libraries.

• Chapters 6 and 7 cover the Client-go Library—the high-level library


to work with the Kubernetes API in Go—and how to unit test code
using this library.

At this point in the book, the reader should be comfortable with building Go
applications working with native resources of the Kubernetes API.

• Chapters 8 and 9 introduce the concept of Custom Resources and


how to work with them in Go.

• Chapters 10 to 12 cover the implementation of Kubernetes Operators


using the controller-runtime library.

• Chapter 13 explores the Kubebuilder SDK, a tool to help develop and


deploy Kubernetes Operators.

By the end of the book, the reader should be able to start building Kubernetes
operators in Go and have a very good understanding of what happens behind the scenes.

xx
CHAPTER 1

Kubernetes API
Introduction
Kubernetes is a platform to orchestrate containers operating in the declarative mode.
There are one-thousand-and-one ways to describe how the Kubernetes platform is
constructed. This book focuses on programming with the platform.
The entry point of the Kubernetes platform is the API. This chapter explores the
Kubernetes architecture by highlighting the central role of the Kubernetes API. It then
focuses on the HTTP REST nature of the Kubernetes API, and on the extensions added to
organize the many resources managed by it.
Finally, you will learn how to navigate the reference documentation effectively to be
able to extract the maximum quantity of useful information daily.

Kubernetes Platform at a Glance


On one side of the chain, the user declares the high-level resources to build applications
to deploy: Deployments, Ingresses, and so on.
In the middle, controllers are activated to transform these resources into low-level
resources (Pods), and the scheduler distributes these resources into nodes. On the other
side of the chain, the node agents deploy the low-level resources onto nodes.
The main elements of the Kubernetes platform (commonly called the control-plane)
are highlighted in Figure 1-1 and described in the following:

1. The API server – this is the central point on the control-plane; the
user and the various pieces of the control-plane contact this API to
create, get, delete, update, and watch resources.

2. The etcd database – this is only accessible by the API Server, is


used to persist the data relative to resources.

1
© Philippe Martin 2023
P. Martin, Kubernetes Programming with Go, https://doi.org/10.1007/978-1-4842-9026-2_1
Chapter 1 Kubernetes API Introduction

3. The Controller manager – this runs the controllers that transform


high-level resources declared by the user into low-level resources
to be deployed on nodes. The controllers are connected to the API
Server, watching for high-level resources and creating, deleting,
and updating low-level resources to satisfy the specifications
declared in high-level resources.

4. Scheduler – this distributes the low-level resources on the various


nodes. The Scheduler is connected to the API Server to watch for
unaffected resources and connect them to nodes.

5. Kubelet – this is an agent running on all nodes of the cluster,


and each agent manages the workloads affected to its node. The
kubelet is connected to the API Server to watch for Pods resources
affected to its node and to deploy the associated containers using
the local container runtime.

6. Kube proxy – this is an agent running on all nodes of the cluster,


and each agent manages the network configurations affected to
its node. The kube proxy is connected to the API Server to watch
for Service resources and to configure associated network rules on
its node.

2
Chapter 1 Kubernetes API Introduction

etcd
Kubectl
---

Control-plane
cre
at watch
de e set
up lete,
d
Controllers
wa ate
tch
API Server crea
te
te
dele te
a
upd
tch
wa

wa ate
tch
up
d
Kubelet
watch

Scheduler
no Kube-proxy
de
s

Figure 1-1. The architecture of Kubernetes

O
 penAPI Specification
The Kubernetes API is an HTTP REST API. The Kubernetes team provides a specification
for this API in the OpenAPI format, either in v2 format at https://github.com/
kubernetes/kubernetes/tree/master/api/openapi-spec or in Kubernetes v1.24,
in v3 format, at https://github.com/kubernetes/kubernetes/tree/master/api/
openapi-spec/v3.
These specifications also are accessible from the API Server at these paths:
/openapi/v2 and /openapi/v3.
An OpenAPI specification is made up of various parts and, among these, are a list of
paths and a list of definitions. The paths are the URLs you use to request this API, and
for each path, the specification gives the distinct operations such as get, delete, or post.
Then for each operation, the specification indicates what are the parameters and body
format for the request, and what are the possible response codes and associated body
format for the response.

3
Another random document with
no related content on Scribd:
SAUCKEL: No, I established no special police; I explained that
yesterday. That was a suggestion put forward by the French units
themselves for protection. At a conference I exaggerated and called
it “police,” but it was not a police force.
M. HERZOG: Have you heard of a “Committee for Social
Peace”?
SAUCKEL: Yes, that was talked about.
M. HERZOG: Have you heard a committee mentioned which
was called the “League for Social Order and Justice?”
SAUCKEL: Yes.
M. HERZOG: Have you ever drafted any order or sent any
instructions which advised the institution of these committees?
SAUCKEL: It was proposed, yes, and it was discussed. As far
as I remember that was in the spring of 1944.
M. HERZOG: And you claim that you never set up these
committees, or drafted any instructions concerning the setting up of
these committees?
SAUCKEL: I have already said that I did that.
M. HERZOG: You admit that you drafted instructions concerning
the formation of these special police forces?
SAUCKEL: That was done on the basis of discussions which I
had with these French units.
M. HERZOG: So you did do this?
SAUCKEL: Yes, in agreement with these French units.
M. HERZOG: Very well.
I submit to the Tribunal Document Number F-827, under Exhibit
Number RF-1518. These are instructions of the Defendant Sauckel
for the formation of these special police forces. The document
consists of several sets of instructions. On Page 6, there is an order
of 25 January 1944 by the Defendant Sauckel.
THE PRESIDENT: Where is it?
M. HERZOG: On Page 6, immediately after Document 1292 in
my document book, you will find the instructions of the Defendant
Sauckel. I read:
“Berlin, 25 January 1944. Secret.
“Subject: Formation of a protection corps for the execution
of the tasks of the Allocation Of Labor in France and in
Belgium during the year 1944.
“1) To the Military Commander in France, Paris.
To the Military Commander for Belgium and Northern
France, Brussels.
“In order to secure the carrying out of the necessary tasks
of the Allocation of Labor in Belgium and France, especially
the assignments for Germany, and to strengthen the
executive, a protective corps, the Committee for Social
Peace, is to be created in France and Belgium. This
protective corps is to consist of indigenous forces with a
nucleus of German police who will act as leaders. This
protective corps will consist of approximately 5,000 men in
France, and approximately 1,000 men in Belgium. I give the
following provisional instructions for the formation of this
protective corps and the accomplishment of its tasks:
“I. Selection of members of the Protective Corps.
“The selection shall be made in close agreement with the
competent Police and SD offices, which shall approve the
candidates, especially from the point of view of their loyalty.
The selection shall be made especially among the
members of political movements favorably disposed to
collaboration with Germany.
“II. Organization of the Protective Corps.
“The Protective Corps will be directed from central offices to
be set up in Paris and Brussels. The heads of these offices
shall be designated by me.”—That is to say, by you,
Defendant Sauckel.—“They shall take orders from my
delegates in France. In purely police questions, the
Protective Corps shall be directed by the Higher SS and
Police Leader. The regional groups of the Protective Corps
shall take orders from the commanders of German police
forces, and the latter will receive technical directions from
the Feldkommandantur and from the recruiting offices as to
their participation in tasks concerning the Allocation of
Labor. The German Police and the services of the SD will
deal with instruction in police matters; technical training, as
far as the Allocation of Labor is concerned, will be given
insofar as is necessary by the experts of the
Feldkommandantur and the recruiting offices.
“The members of the Protective Corps will not wear
uniform; they will however, carry firearms.
“III. Execution of orders.
“The members of the Protective Corps assigned to the
recruiting offices or to the Feldkommandantur shall be
employed in such a way as to insure maximum efficiency in
the execution of measures ordered. For example, they must
be informed immediately if Frenchmen who have been
summoned by German offices do not appear. They must
find out the domiciles of these persons and bring them to
report in accordance with instructions from the German
police leader in collaboration with the French and German
police. Furthermore, they must track down immediately all
those who have refused to appear when summoned, and
those who have broken their contracts. In the interests of an
effective executive, it is expedient that they receive
regularly lists of persons summoned and persons liable for
service, to enable them to act immediately in cases where
German directives have not been complied with.
“It is to be presumed that these quick methods, coupled
with fitting punishment and immediate publication of the
punishments, will have a more deterrent effect than that
achieved by tracking down the men afterwards, as has
been done up to now. Furthermore, members of the
Protective Corps are to keep the German offices informed
of any particular difficulties in recruitment....”
And all that, Defendant, is signed “Sauckel.” Do you still claim
that you did not form a special police corps in France and Belgium?
SAUCKEL: I already told my attorney yesterday that in
agreement with French organizations such a protective corps was
set up, so that on the one hand people who wanted to work could be
protected, and on the other hand administrative measures could be
carried out. Since the Frenchmen themselves declared that they
were ready and willing to collaborate, I did not see anything
unfavorable in this or anything that was in any way out of order.
It was to alleviate the conditions of the indigenous people
themselves.
M. HERZOG: I ask you to answer my question “yes” or “no.” Do
you admit that you set up this special police service?
SAUCKEL: I admit that I suggested this Protective Corps, and
that it was set up, but only on a small scale.
M. HERZOG: Is it true that you issued instructions, or imposed
measures of constraint against those who evaded the compulsory
labor service?
SAUCKEL: I did not issue them myself, but rather the French
Government did. That is correct; for in every occupied territory—and
that is true the whole world over—the authority of the occupying
power must be respected.
M. HERZOG: Is it true that you demanded that the death penalty
should be applied to officials who, for instance, hindered your
action?
SAUCKEL: It is true that at a conference with the French
Premier Laval, I demanded, by way of negotiations, the death
penalty in cases of very serious obstruction.
M. HERZOG: Then you admit that you demanded the
application of the death penalty in the case of these officials?
SAUCKEL: Yes, if a serious case of sabotage was in question—
according to martial law.
M. HERZOG: Is it true that your task was to procure for the
German war industry the labor it required?
SAUCKEL: That was one of my tasks.
M. HERZOG: In this respect were you responsible to the
Defendant Speer, Minister for Armaments and Munitions, for the
carrying out of your task?
SAUCKEL: I was responsible to the Four Year Plan and to the
Führer, and I had instructions from the Führer to meet the
requirements of Reich Minister Speer as far as it was possible for me
to do so.
M. HERZOG: Did the Defendant Speer approve of all the steps
which you took in recruiting foreign labor?
SAUCKEL: At all events he agreed, or he demanded, that
workers should be put at his disposal. Sometimes, however, we did
not entirely agree as to how it should be done; for instance, we did
not agree about the protected factories in France.
M. HERZOG: We will come to that later. I ask you to tell me
whether you always succeeded in satisfying the demands for
workers which were made to you by the different sections of German
industry?
SAUCKEL: No, I was not always successful.
M. HERZOG: And when you failed, did the orders that were sent
to you by Defendant Speer have to have priority over all others?
SAUCKEL: Yes, they had to have priority.
M. HERZOG: Were there not incidents in this respect? For
instance, did it not happen that some transports of workers were
diverted from their original destination on instructions from
Defendant Speer?
SAUCKEL: It did happen that, contrary to my instructions, labor
transports were stopped, or transferred to other regions or to other
factories. But whether the order always emanated from Herr Speer,
or from an armament commission, or from another office, I do not
know. It was not always from the same quarter.
M. HERZOG: In your interrogatory you declared, however, that
the original destination of these transports was sometimes changed
in order to satisfy the demands of Speer’s offices. Do you confirm
this?
SAUCKEL: Yes; but I meant by that something rather different.
In that case I was informed about it. There were two kinds of
changes, or deviations: those which I did not know about, and those
which were agreed upon.
M. HERZOG: Will you tell the Tribunal what was understood by
the “red ticket” system?
SAUCKEL: The red ticket system was applied when there was a
demand for workers, mostly specialized or skilled workers, which
had to take priority over all other demands because the work was
necessary.
M. HERZOG: The system of the red ticket was applied to the
armament industry, was it not?
SAUCKEL: The red ticket system was applied to the armament
industry...
M. HERZOG: And it was established by agreement between the
Defendant Speer and yourself?
SAUCKEL: That was a system which, in my opinion, was always
intended to meet emergencies; there were variations, such as lists or
red tickets. Originally, there were only lists, and the red ticket was
added by decree.
M. HERZOG: You therefore admit that by these various systems
you share with the Defendant Speer the responsibility of having
compelled workers to work in German factories for the needs of the
war which Germany was fighting against their own native lands?
SAUCKEL: I should like to emphasize particularly that this red
ticket system did not apply only to foreign workers; it applied
especially to German workers too—German skilled workers.
M. HERZOG: But it was applied also to foreign workers?
SAUCKEL: It applied to foreign workers as well, if they were
specialists and declared their willingness.
M. HERZOG: Will you tell the Tribunal what is meant by the
“blocking” of factories?
SAUCKEL: A factory was “blocked” if it was manufacturing
articles which were not essential for war, or if it was a question of so-
called luxury articles.
M. HERZOG: I do not think you understood my question. What
were, for instance, the “S” factories in France—the factories
protected by Speer?
SAUCKEL: “Sperrbetriebe” known as “S” factories—is that what
you mean?
M. HERZOG: Yes.
SAUCKEL: Sperrbetriebe were factories which worked for Speer
in France, which had been agreed to by the French Minister
Bichelonne, and they were blocked as far as labor recruitment was
concerned.
M. HERZOG: Did you not exert strong pressure on the
Defendant Speer to get him to abandon the practice of blocking
industries?
SAUCKEL: I asked him and I urged him, but I could not succeed
in putting an end to the blocking of these factories.
M. HERZOG: Did you ever bring up the matter with Hitler and
insist that Speer should give up his position?
SAUCKEL: Yes, I was very insistent with Hitler about it, but I had
no success.
M. HERZOG: In this connection did you not ask the Führer to
increase your powers at the expense of the Defendant Speer?
SAUCKEL: I did not ask for a general extension of my powers,
but I asked that conditions should be allowed to remain as they had
been previously, for—I ask to be permitted to explain this to the
Tribunal—my task was to bring workers from France to Germany—
may I make this statement:
The departments under Speer demanded skilled workers from
me. There were skilled workers already in the factories which Speer
had blocked. Similar industries in Germany would, of course, be
worse off if instead of having skilled French workers they were
supplied with unskilled French workers, or men without experience in
that particular trade. I had to procure workers in any case, but I
considered it wiser for German economy to procure for it the right
kind of workers and not workers who were unskilled.
M. HERZOG: I beg the Tribunal to turn back to Document
Number 3819-PS, the second part of 3819-PS. It consists of two
letters, each addressed to the Führer, by the Defendant Sauckel and
by the Defendant Speer, on this subject of the blocking of industries.
First of all, I will read to the Tribunal some extracts from
Sauckel’s letter, which happens to be the second.
THE PRESIDENT: Have these not both been read already?
M. HERZOG: I think they have already been read, Mr.
President; I cannot affirm it, but believe so. Document Number 3819-
PS has already been submitted to the Tribunal as Exhibit Number
GB-306. If the Tribunal wishes, I can limit myself to very short
extracts.
THE PRESIDENT: You need not read them for the purpose of
your question of the defendant.
M. HERZOG: [Turning to the defendant.] In this letter, on Page
27, you asked whether you could obtain in a general manner a free
hand for the rational utilization of labor.
Do you admit that you asked the Führer for this free hand?
SAUCKEL: I have not found the place. I could never have asked
for a free hand, but I did ask to be permitted to recruit as before. I
cannot find the place that you are quoting.
M. HERZOG: You will find it on Page 27.
SAUCKEL: In this German text it says: “In this situation, it is
absolutely necessary that I should again have a free hand.” That
means that I should have a free hand once again, as I had had
before the blocked industries were instituted. That is correct, for I
was interested in a rational use of labor.
M. HERZOG: That is what I asked you to confirm. Did you ask
that your powers should be increased at the expense of those of
your Codefendant Speer? Will you answer “yes” or “no,” if you can?
SAUCKEL: I do not understand the question. Was it obtain them
or ask for them?
M. HERZOG: Ask for them.
SAUCKEL: Yes, I asked for them, for it was to Speer’s
advantage.
M. HERZOG: You asked for that?
SAUCKEL: Yes, I asked for that in the interests of my tasks.
M. HERZOG: And do you not remember that on other
occasions, the Defendant Speer likewise asked that his powers
should be increased at the expense of yours?
SAUCKEL: Yes, that might have happened also.
M. HERZOG: You declared in your interrogatory that the very
close relations between Speer and Goebbels after the fall of
Stalingrad made Speer want particularly to have you under his
authority. Can you confirm this?
SAUCKEL: Yes.
M. HERZOG: Is it true that your general program for recruiting
labor included the employment of prisoners of war?
SAUCKEL: The employment of prisoners of war as far as they
should and could be put to work under the care of the Wehrmacht.
M. HERZOG: Do you remember the decree which we
mentioned this morning, your Decree Number 10, which stipulated
the order of priority of work and gave priority to armament? Was this
order applicable to prisoners of war as well?
SAUCKEL: As I explained yesterday, this decree was applicable
to prisoners of war only by way of exchange, and to the extent as set
forth in the rules of work issued by the OKW and by me in a catalog
of work.
M. HERZOG: But Article 8 of this decree stipulates only that it
was applicable to prisoners of war.
SAUCKEL: Yes, in accordance, of course, with the other
decrees which existed; that was a matter of course.
M. HERZOG: You spoke to us yesterday about inspectorates. Is
it true that in September 1943 you came to an agreement with Dr.
Ley concerning the setting up of a central inspectorate for foreign
workers?
SAUCKEL: Yes, for the purposes of their welfare.
M. HERZOG: In consequence, you admit that you are
responsible for the measures concerning the treatment of foreign
workers?
SAUCKEL: I am responsible for the directives which I issued;
they are all available.
M. HERZOG: Do you consider yourself responsible for the
feeding of foreign workers?
SAUCKEL: I consider myself responsible for the directives
which I issued regarding the feeding of foreign workers. The actual
feeding of these people was not the task and responsibility of the
labor authorities. That was the responsibility of the factories, or the
camp leaders who had been charged by the factories to look after
this.
M. HERZOG: I am going to have submitted to you Document
Number 025-PS. This document was submitted to the Tribunal under
Exhibit Number USA-698. You already had it yesterday. It consists of
the report of a meeting in the office of the Plenipotentiary General for
the Allocation of Labor—that is to say, you yourself—on 3
September 1942. The document is dated 4 September.
This document, Mr. President, is at the end of my document
book, after Document F-827, the last page of the French translation.
I read:...
THE PRESIDENT: The last page is Document F-857, is it not?
The document called 857—the last page I have got. It is just in front
of Document 2200-PS. Did you come across that? It is just after
Document 1913-PS.
M. HERZOG: After Document 1913-PS, Mr. President.
THE PRESIDENT: Yes.
M. HERZOG: I read:
“The Führer cannot understand that, in the struggle for the
future of Europe, the country which has to bear the brunt of
this struggle is the one to suffer most from hunger; whereas
in France...”
THE PRESIDENT: It is on Page 1 or Page 4?
M. HERZOG: No, Mr. President, on Page 4 of the French text—
that is to say, on the last page.
“The Führer cannot understand that, in the struggle for the
future of Europe, the country which has to bear the brunt of
this struggle is the one to suffer most from hunger; whereas
in France, in Holland, in Hungary, in the Ukraine, or
anywhere else, there is no talk of hunger. He desires that it
should be the reverse in the future. As regards the foreign
workers living in the Reich—with the exclusion of the
Eastern Workers—little by little their rations must be
reduced and made to correspond to their output. It is not
admissible that lazy Dutchmen or Italians should receive
better rations than good Eastern Workers. In principle the
guiding rule of utmost output must apply equally to feeding.”
[Turning to the defendant.] I ask you what you meant when you
stated that, “In principle the guiding rule of utmost output must apply
equally to feeding?”
SAUCKEL: There was a standard ration in the Reich which was
increased by additional rations based on output or performance. I
fought for the principle that these additional rations, which the
workers from the West were already largely receiving, should be
granted to the workers from the East as well; and that where western
workers—that is, Dutch and Belgian workers—did not keep up their
output in the same way as the Eastern Workers, these additional
rations should be cut down accordingly, but not the standard ration
which applied to the German people as well.
M. HERZOG: You therefore consider that if the output of one
worker is smaller than that of another, his food rations must be
smaller. Is that what I am to understand?
SAUCKEL: No, it is not right to interpret it that way. I should like
to explain the system again. In Germany each worker received his
ration as fixed by the Reich Minister for Food. In addition to that
there were special increases as a reward for increased output. At the
beginning these additional rations were not granted to Russian
workers, and it is these additional rations we are dealing with here;
not with starving people, or cutting down their standard food rations
—additional rations for increased output.
THE PRESIDENT: Perhaps we had better adjourn now.
[A recess was taken.]

MARSHAL: If it pleases the Tribunal, the report is made that the


Defendant Raeder is absent.
THE PRESIDENT: M. Herzog, do you anticipate being able to
conclude your cross-examination before half past 4?
M. HERZOG: Yes, Mr. President, I think that I might even finish
before that.
THE PRESIDENT: Very well.
M. HERZOG: Defendant Sauckel, I offered in evidence this
morning Document Number F-810, which is an account of the
conference which you held on 15 and 16 July 1944 at Wartburg with
the heads of the regional labor offices. Do you remember?
SAUCKEL: Yes, I remember.
M. HERZOG: Do you remember whether during this conference
the question was raised as to the discipline to be imposed upon the
workers?
SAUCKEL: It is possible that during this conference—or
conferences—this question was discussed. I cannot remember
exactly; I did not participate in all the sessions.
M. HERZOG: Do you know Ministerialrat Dr. Sturm?
SAUCKEL: Ministerialrat Dr. Sturm is not personally known to
me.
M. HERZOG: Do you remember the statements made at the
conference of 15 and 16 July 1944 by Dr. Sturm?
SAUCKEL: I cannot remember any particular statements by Dr.
Sturm.
M. HERZOG: I shall hand you once more the minutes of that
meeting. It is Document Number F-810 which was presented this
morning under Exhibit Number RF-1507. Will you please look at
Page 25 of the German text. It is also Page 25 of the French version.
There you see—I read the first line: “Sturm gave the following report
from his sector on work discipline.”
I shall pass to the next page, where I read, “We are working with
the Gestapo...”
THE PRESIDENT: Where is this?
M. HERZOG: Document F-810, Mr. President; it is a document
which is marked...
THE PRESIDENT: I know it is 806, but I thought you told us that
they followed on.
M. HERZOG: 810, Sir, 810.
THE PRESIDENT: I have got that.
M. HERZOG: Page 25.
THE PRESIDENT: Yes, go on.
M. HERZOG: With your permission, I will begin again.
“Sturm gave the following report from his sector on work
discipline...”
And on the following page: “We are working with the Gestapo
and the concentration camps, and we are certainly on the right
track.”
Did you make any observations when that statement was
made?
SAUCKEL: I did not hear that statement myself. He gave a
specialized report on questions of labor legislation, as it says at the
beginning. I am seeing the record for the first time in my life. There
were several parallel meetings at the same time. I did not hear it
myself, but it stands to reason that some sort of ruling regarding
penalties had to be made, as is done in all labor legislation.
Perhaps I may read to you from the same document, the
beginning:
“Measures regulating the employment of labor and wages
are only possible on the basis of a healthy working morale.
Regulations of a disciplinary and penal character for
securing such morale require unified handling, the details of
which will be dealt with at a subsequent meeting of experts
on penal law.”
That is, of course, not one of my offices.
M. HERZOG: I asked you what you thought of Dr. Sturm’s
statement.
SAUCKEL: May I read in connection with Dr. Sturm’s statement,
at the end of the first page...
M. HERZOG: Will you please answer my question first? What
do you think of this statement?
SAUCKEL: I have already answered.
M. HERZOG: Please answer my question. What do you think of
this statement?
SAUCKEL: I did not know of this statement, as Sturm, I believe,
came from some other department. I do not know whether he
belonged to the Ministry of Labor itself, or to some other department;
that I cannot say. I did not hear these statements...
THE PRESIDENT: Watch the light. Do you not see the light in
front of you?
M. HERZOG: Do you not remember that an agreement was
reached between you and the Chief of the Police and SS to hand
over to the Gestapo those workers who were guilty of leaving their
work?
SAUCKEL: Well, there had to be an authority in Germany which
dealt with workers who left their places of work without being entitled
to do so. It could not have been done by any authority other than the
Police; there was no other way. In connection with this document I
beg to be allowed to read some more from Page 1:
“Apart from that, the number of penalties imposed by the
authorities on German workers, such as reprimands, fines,
concentration camps, and legal penalties, was relatively
surprisingly small. In cases dealt with by the public
prosecutor the penalties inflicted amounted on an average
to 0.1 to 0.2 for every 1,000 workers.”
M. HERZOG: What has that to do with the question which I
asked you about your relations with the Gestapo and the
concentration camps?
SAUCKEL: But there was no other authority except the police
who could make an arrest if it were necessary and legally justified by
court rulings.
M. HERZOG: You admit, then, that it was with your agreement
that the Gestapo proceeded to arrest workmen who had broken what
you call their contract of work, and send them to concentration
camps?
SAUCKEL: Not to concentration camps, no, but into the custody
which was prescribed. The penalties were decreed in accordance
with certain regulations. I made no other agreement.
M. HERZOG: I submit in evidence Document Number 2200-PS;
which becomes Exhibit Number RF-1519. It is a service
memorandum of the Gestapo addressed to the district police officials
of the Cologne and Aachen districts. It refers to the struggle against
breaches of contract on the part of foreign workers. Mr. President, it
is the fourth document from the end in my document book. I read
from it:
“The considerable number of refractory foreign workers ... is
dangerous to the security of the Reich.... There is always
danger of actual sabotage in such cases, ... the
Reichsführer SS and Chief of the German Police has
reached an agreement with the Plenipotentiary General for
the Allocation of Labor that all charges of absenteeism
against foreign workers shall be dealt with by the Gestapo.
“...the district police authorities are expected to examine
anything bearing on this matter. They are authorized by me
to give warnings to absentees by order of the Gestapo
State Police office, Cologne, and to order corrective
custody up to 3 days for all cases of minor importance. The
instructions concerning the attitude to be taken toward the
individual groups of foreign workers are to be noted....
“In more serious cases of absenteeism the district police
authorities will submit the files concerning the cases to the
competent Gestapo office (Cologne, Aachen, or Bonn) for
decision. The Gestapo will examine the matter and order
the necessary measures—detention, sending to corrective
labor camps, or concentration camps.”
[Turning to the defendant.] Do you still deny that it was with your
agreement that refractory workers were first handed over to the
Gestapo, and then sent to concentration camps?
SAUCKEL: I did not deny it, but as stated in the first paragraph,
this only happened if public order was disturbed by punishable
offenses, that is in serious cases, or when there were breaches of
working contracts. There was nobody except the police to undertake
the search for such people, and I consider the procedure to be
perfectly correct.
M. HERZOG: You think that it is a correct manner of procedure
to hand over foreign workers to the Gestapo and to concentration
camps? I note your answer.
SAUCKEL: Only in the case of serious offenses. It says “in
serious cases” in the document. That was the demand imposed on
me.
M. HERZOG: At what period did you learn about the atrocities
which were committed in concentration camps?
SAUCKEL: I can say with a good conscience that I gained
knowledge here of the cruelties which were committed in the
concentration camps; after the collapse of the Reich.
M. HERZOG: Do you think that it was the same with all the
Hitlerite chiefs?
SAUCKEL: I cannot speak for the others. I myself did not know
of such measures, which I abhor and which I only learned of here.
M. HERZOG: Do you think that the Reichsführer SS Himmler,
for example, was aware of the atrocities which were committed in the
concentration camps?
SAUCKEL: I cannot say whether the Reichsführer SS knew of
them, whether he himself instigated them. During the whole of my
career I hardly ever spoke to the Reichsführer SS because our
personal relations were rather strained.
M. HERZOG: During the interrogation by your counsel
yesterday you declared that you once visited the concentration camp
of Buchenwald; did you not?
SAUCKEL: Yes, in 1937 or 1938. I cannot tell you that from
memory now.
M. HERZOG: You declared you made this visit in the company
of an Italian commission, did you not?
SAUCKEL: Yes, that is correct.
M. HERZOG: Do you know that there is in existence an album
of official photographs of the concentration camp in Buchenwald?
SAUCKEL: I do not know that.
M. HERZOG: I offer that album in evidence to the Tribunal under
Exhibit Number RF-1520. It bears the Document Number D-565. It is
a document of the British Delegation.
[Turning to the defendant.] Do you recognize yourself in these
photographs?
SAUCKEL: Yes, I recognize myself in this picture.
M. HERZOG: With whom are you there?
SAUCKEL: That is the Reichsführer SS.
M. HERZOG: Himmler?
SAUCKEL: Himmler, yes.
M. HERZOG: Thank you. And you contend that you, a Gauleiter
and Reichsstatthalter of Thuringia, visited the Buchenwald
Concentration Camp in the company of the Reichsführer SS, and—I
call your attention to this—in the company of the commander of the
camp, without knowledge of what was happening inside the camp?
SAUCKEL: I cannot tell you when this picture was taken or
whether it was taken in the camp itself. I was once outside the camp
together with the Reichsführer SS—there was another large site
there—but I was never inside the camp together with the
Reichsführer SS. I was there only once with an Italian commission.
This picture does not show that there was an inspection. Here
you see some troops lined up...
M. HERZOG: The Tribunal will decide about that.
I offer in evidence under Exhibit Number RF-1521 the certificate
establishing the origin of this album.
In October of 1945 you were interrogated on the expulsion of
Jews from industry. You said this:
“I never had anything to do with it. I had nothing to do with
the question of the eviction of Jews from industry. I had no
influence in this matter. It was an enigma to me.”
Can you confirm this declaration?
SAUCKEL: That is perfectly correct. I did not say the eviction of
the Jews from industry was a secret to me; I said that, to the best of
my recollection, I had nothing to do with it.
M. HERZOG: Your counsel gave you a document yesterday,
Document Number L-61, which you thought you had to contest.
SAUCKEL: Yes.
M. HERZOG: The point that you raised against this document
was that it was dated 1942, and that it dealt with questions prior to
your appointment. Did I understand you correctly yesterday?
SAUCKEL: The enclosures to the document deal with questions
that had already been started before I was appointed.
M. HERZOG: I offer in evidence Document Number L-156,
which becomes Exhibit Number RF-1522. It is a letter written under
the authority of the Delegate for the Four Year Plan, the
Plenipotentiary General for the Allocation of Labor, which is you. It is
dated 26 March 1943. It is addressed to the chiefs of the regional
labor offices, and it deals with the question of the eviction of Jews. It
begins thus:
“In agreement with me and the Reich Minister for
Armaments and Munitions, the Reichsführer SS, for
reasons of state security, removed from their place of work
at the end of February such Jews as were not living in
camps and who were working as free workers.
“They have been formed into working units or assembled
for deportation. In order not to endanger the efficacy of this
measure, I have avoided issuing any notification
beforehand, and I have notified only those regional labor
offices in whose districts free Jewish manpower was
employed in large numbers.
“So as to have a general view of the effect of those
measures on the manpower position, I ask you to let me
have, as from 31 March 1943, returns showing how many
Jews were removed from their work, and how many it has
been found necessary to replace by other workers.
“When giving the numbers of the factories and of the Jews
employed by them, one should take into account the
situation which existed before the evacuation. The enclosed
form should be used for making reports, et cetera.”
Do you still say that you had no part in the matter of the eviction
of Jews and their replacement by foreign workers?
SAUCKEL: Here again I must state emphatically that this letter
was never put before me. It has no signature, and here again it
comes from a subdivision in the Reich Ministry of Labor at 96
Saarlandstrasse. Some official dealt with it there. I myself have
absolutely no recollection of having ever had knowledge of this letter.
I did not write it, it does not come from my office, it has been written
“by order,” and the signature is not mine.
M. HERZOG: Will you please look on the left in the corner. It
says:
“The Delegate for the Four Year Plan, the Plenipotentiary
General for the Allocation of Labor.” Is not that you? You talk of a
subordinate. Are you trying to throw the responsibility on one of your
subordinates?
SAUCKEL: No, I do not want to do that. I merely want to say
that the letterhead belongs to some office, but I have never known
anything about the letter. This is the first time in my life that I have
seen it, and I myself did not have it written. I can say that under oath.
M. HERZOG: With this letter is an application form for
replacement for the expelled Jews. Who else but you could have
anything to do with this, you who were the Plenipotentiary General
for the Allocation of Labor?
SAUCKEL: Yes, my department—I told my counsel yesterday
that my department, of course, had to furnish replacements if
workers were taken away from a concern, either by being called up
for service or for some other measure. I did not always know the
details.
M. HERZOG: You are not answering my question, the fact that
this letter...
SAUCKEL: Yes, I have answered your question properly.
M. HERZOG: The fact that this letter contains an application
relating to the replacement of workers, is that not proof that it comes
from your department, you being the Plenipotentiary General for the
Allocation of Labor?
SAUCKEL: Such a request could not come from my department.
The evacuation of Jews was entirely the responsibility of the
Reichsführer SS. I had only troubles because of such measures, as
it was very difficult to replace workers. I had no interest in it.
M. HERZOG: In short, you deny that you ever proposed special
working conditions for Jews?
SAUCKEL: That is just what I am denying. I had nothing to do
with it. It was not my task.
M. HERZOG: Would you please refer once more to Document
Number F-810, which I offered under Exhibit Number RF-1507? We
will hand it to you if you have not got it. Please look at Page 16,
under the heading: “Gauleiter Sauckel.” I quote...
SAUCKEL: I have not the document at hand—oh yes, I think I
have it.
M. HERZOG: It was passed to you about 2 minutes ago. If you
have not got it, it will be handed to you again.
SAUCKEL: Will you please give me the number again?
M. HERZOG: Document F-810, but I do not think it is marked on
the photostat you have. Have you that document?
SAUCKEL: Yes.
M. HERZOG: Under the heading “Gauleiter Sauckel,” I read—it
is on Page 16 of the document:

You might also like