LEADER 11816nam 2200553 450 001 9910637739503321 005 20230424103558.0 010 $a1-4842-9026-7 024 7 $a10.1007/978-1-4842-9026-2 035 $a(MiAaPQ)EBC7164105 035 $a(Au-PeEL)EBL7164105 035 $a(CKB)25849085000041 035 $a(OCoLC)1356574762 035 $a(OCoLC-P)1356574762 035 $a(CaSebORM)9781484290262 035 $a(EXLCZ)9925849085000041 100 $a20230424d2022 uy 0 101 0 $aeng 135 $aurcnu|||||||| 181 $ctxt$2rdacontent 182 $cc$2rdamedia 183 $acr$2rdacarrier 200 10$aKubernetes programming with Go $eprogramming Kubernetes clients and operators using Go and the Kubernetes API /$fPhilippe Martin 210 1$aNew York, NY :$cApress,$d[2022] 210 4$d©2022 215 $a1 online resource (326 pages) 300 $aIncludes index. 311 08$aPrint version: Martin, Philippe Kubernetes Programming with Go Berkeley, CA : Apress L. P.,c2023 9781484290255 327 $aIntro -- Table of Contents -- About the Author -- About the Technical Reviewers -- Acknowledgments -- Introduction -- Chapter 1: Kubernetes API Introduction -- Kubernetes Platform at a Glance -- OpenAPI Specification -- Verbs and Kinds -- Group-Version-Resource -- Sub-resources -- Official API Reference Documentation -- The Deployment Documentation -- Operations Documentation -- The Pod Documentation -- One-Page Version of the Documentation -- Conclusion -- Chapter 2: Kubernetes API Operations -- Examining Requests -- Making Requests -- Using kubectl as a Proxy -- Creating a Resource -- Getting Information About a Resource -- Getting the List of Resources -- Cluster-wide -- In a Specific namespace -- Filtering the Result of a List -- Using Label Selectors -- Using Field Selectors -- Deleting a Resource -- Deleting a Collection of Resources -- Updating a Resource -- Managing Conflicts When Updating a Resource -- Using a Strategic Merge Patch to Update a Resource -- Patching Array Fields -- Special Directives -- replace Directive -- delete Directive -- deleteFromPrimitiveList Directive -- setElementOrder Directive -- Applying Resources Server-side -- Watching Resources -- Filtering During a Watch Session -- Watching After Listing Resources -- Restarting a watch Request -- Allowing Bookmarks to Efficiently Restart a watch Request -- Paginating Results -- Consistency of the Full List -- Detecting the Last Chunk -- Getting Results in Various Formats -- Getting Results as a Table -- Column Definitions -- Row Data -- Using the YAML Format -- Using the Protobuf Format -- Conclusion -- Chapter 3: Working with API Resources in Go -- API Library Sources and Import -- Content of a Package -- types.go -- register.go -- doc.go -- generated.pb.go and generated.proto -- types_swagger_doc_generated.go -- zz_generated.deepcopy.go -- Specific Content in core/v1. 327 $aObjectReference -- ResourceList -- Taint -- Toleration -- Well-Known Labels -- Writing Kubernetes Resources in Go -- Importing the Package -- The TypeMeta Fields -- The ObjectMeta Fields -- Name -- Namespace -- UID, ResourceVersion, and Generation -- Labels and Annotations -- OwnerReferences -- Setting APIVersion and Kind -- Setting Controller -- Setting BlockOwnerDeletion -- Spec and Status -- Comparison with Writing YAML Manifests -- A Complete Example -- Conclusion -- Chapter 4: Using Common Types -- Pointers -- Getting the Reference of a Value -- Dereferencing a Pointer -- Comparing Two Referenced Values -- Quantities -- Parsing a String as Quantity -- Using an inf.Dec as a Quantity -- Using a Scaled Integer as a Quantity -- Operations on Quantities -- IntOrString -- Time -- Factory Methods -- Operations on Time -- Conclusion -- Chapter 5: The API Machinery -- The Schema Package -- Scheme -- Initialization -- Mapping -- Conversion -- Adding Conversion Functions -- Converting -- Serialization -- JSON and YAML Serializer -- Protobuf Serializer -- Encoding and Decoding -- RESTMapper -- Kind to Resource -- Resource to Kind -- Finding Resources -- The DefaultRESTMapper Implementation -- Conclusion -- Chapter 6: The Client-go Library -- Connecting to the Cluster -- In-cluster Configuration -- Out-of-Cluster Configuration -- From kubeconfig in Memory -- From a kubeconfig on Disk -- From a Personalized kubeconfig -- From Several kubeconfig Files -- Overriding kubeconfig with CLI Flags -- Getting a Clientset -- Using the Clientset -- Examining the Requests -- Creating a Resource -- Getting Information About a Resource -- Getting List of Resources -- Filtering the Result of a List -- Setting LabelSelector Using the Labels Package -- Using Requirements -- Parsing a LabelSelector String -- Using a Set of Key-value Pairs. 327 $aSetting Fieldselector Using the Fields Package -- Assembling One Term Selectors -- Parsing a FieldSelector String -- Using a Set of Key-Value Pairs -- Deleting a Resource -- Deleting a Collection of Resources -- Updating a Resource -- Using a Strategic Merge Patch to Update a Resource -- Applying Resources Server-side with Patch -- Server-side Apply Using Apply Configurations -- Building an ApplyConfiguration from Scratch -- Building an ApplyConfiguration from an Existing Resource -- Watching Resources -- Errors and Statuses -- Definition of the metav1.Status Structure -- Error Returned by Clientset Operations -- RESTClient -- Building the Request -- Executing the Request -- Exploiting the Result -- Getting Result as a Table -- Discovery Client -- RESTMapper -- PriorityRESTMapper -- DeferredDiscoveryRESTMapper -- Conclusion -- Chapter 7: Testing Applications Using Client-go -- Fake Clientset -- Checking the Result of the Function -- Reacting to Actions -- Checking the Actions -- Fake REST Client -- FakeDiscovery Client -- Stubbing the ServerVersion -- Actions -- Mocking Resources -- Conclusion -- Chapter 8: Extending Kubernetes API with Custom Resources Definitions -- Performing Operations in Go -- The CustomResourceDefinition in Detail -- Naming the Resource -- Definition of the Resource Versions -- Converting Between Versions -- Schema of the Resource -- Deploying a Custom Resource Definition -- Additional Printer Columns -- Conclusion -- Chapter 9: Working with Custom Resources -- Generating a Clientset -- Using deepcopy-gen -- Installing deepcopy-gen -- Adding Annotations -- Running deepcopy-gen -- Using client-gen -- Installing client-go -- Adding Annotations -- Adding AddToScheme Function -- Running client-go -- Using the Generated Clientset -- Using the Generated fake Clientset -- Using the Unstructured Package and Dynamic Client. 327 $aThe Unstructured Type -- Getters and Setters to Access TypeMeta Fields -- Getters and Setters to Access ObjectMeta Fields -- Methods for Creating and Converting -- Helpers to Access Non-meta Fields -- Example -- The UnstructuredList Type -- Getters and Setters to Access TypeMeta Fields -- Getters and Setters to Access ListMeta Fields -- Methods for Creating and Converting -- Converting Between Typed and Unstructured Objects -- The Dynamic Client -- Getting the dynamic Client -- Working with the dynamic Client -- Example -- The fake dynamic Client -- Conclusion -- Chapter 10: Writing Operators with the Controller-Runtime Library -- The Manager -- The Controller -- Creating a Controller -- Watching Resources -- A First Example -- Using the Controller Builder -- A Second Example Using the ControllerBuilder -- Injecting Manager Resources into the Reconciler -- Passing the Values When Creating the Reconciler Structure -- Using Injectors -- Using the Client -- Getting Information About a Resource -- Listing Resources -- Creating a Resource -- Deleting a Resource -- Deleting a Collection of Resources -- Updating a Resource -- Patching a Resource -- Server-side Apply -- Strategic Merge Patch -- Merge Patch -- Updating the Status of a Resource -- Patching the Status of a Resource -- Logging -- Verbosity -- Predefined Values -- Logger Name -- Getting the Logger from Context -- Events -- Conclusion -- Chapter 11: Writing the Reconcile Loop -- Writing the Reconcile Function -- Checking Whether the Resource Exists -- Implementing the Reconciled Resource -- Simple Implementation Example -- Conclusion -- Chapter 12: Testing the Reconcile Loop -- The envtest Package -- Installing envtest Binaries -- Using envtest -- Defining a ginkgo Suite -- Writing the Tests -- Test 1 -- Test 2 -- Test 3 -- Test 4 -- Conclusion -- Chapter 13: Creating an Operator with Kubebuilder. 327 $aInstalling Kubebuilder -- Creating a Project -- Adding a Custom Resource to the Project -- Building and Deploying Manifests -- Running the Manager Locally -- Personalizing the Custom Resource -- Editing the Go Structures -- Enabling the Status Subresource -- Defining Printer Columns -- Regenerating the Files -- Implementing the Reconcile Function -- Adding RBAC Annotations -- Deploying the Operator on the Cluster -- Creating a New Version of the Resource -- Defining a New Version -- Implementing Hub and Convertible -- Setting Up the webhook -- Updating kustomization Files -- Using Various Versions -- Conclusion -- Index. 330 $aThis book begins by introducing the structure of the Kubernetes API and which operations it serves. Following chapters demonstrate how to write native Kubernetes resources definitions using Go structures defined in the API and API Machinery libraries. Miscellaneous utilities are described to help you work with different resource fields and to convert your resource definitions to or from YAML or JSON. Next, you will learn how to interact with the Kubernetes API server to create, delete, update, and monitor resources in a cluster using the client-go library. A complete chapter is devoted to tools provided to test your programs using the client-go library. An example follows to wrap up the first part of the book, describing how to write a kubectl plugin. Next, you will learn how to extend the Kubernetes API using Custom Resource Definitions, and how to write Kubernetes resources in a generic way as well as how to create your own resources using the unstructured concept. The next chapters delve into the controller-runtime library, useful for extending Kubernetes by writing operators, and the kubebuilder framework, which leverages this library, to help you start writing operators in minutes. After reading this book, you will have a deep understanding of the Kubernetes API's structure and how Kubernetes resources are organized within it, and have at your disposal a complete toolbox to help you write Kubernetes clients and operators. What You Will Learn Understand how the Kubernetes API and its resources are organized Write Kubernetes resources in Go Create resources in a cluster Leverage your newly-gained knowledge to write Kubernetes clients and operators Who is this Book for: Software engineers and (Site Reliability Engineers) SREs wishing to write Kubernetes clients and operators using the Go language. 606 $aGo (Computer program language) 606 $aSoftware container technologies 606 $aApplication software$xDevelopment 615 0$aGo (Computer program language) 615 0$aSoftware container technologies. 615 0$aApplication software$xDevelopment. 676 $a005.3 700 $aMartin$b Philippe$0200316 801 0$bMiAaPQ 801 1$bMiAaPQ 801 2$bMiAaPQ 906 $aBOOK 912 $a9910637739503321 996 $aKubernetes Programming with Go$93000254 997 $aUNINA