Welcome to my GitHub

Github.com/zq2599/blog…

Content: all original article classification summary and supporting source code, involving Java, Docker, Kubernetes, DevOPS, etc.;

Links to articles

  1. Client-go: Preparation
  2. Client-go Actual combat 2 :RESTClient
  3. Client go: Clientset
  4. Client-go: dynamicClient
  5. Client-go Combat 5: Discover Client

About the client – go

  • Client-go is kubernetes official provide go language client library, go application using the library can access Kubernetes API Server, so we can program to kubernetes resources to add, delete, change, check operation;
  • In addition to providing rich apis for manipulating Kubernetes resources, client-Go also provides important support for controllers and operators, as shown below. The client-go informer mechanism can bring the resource changes that the controller cares about to the controller in time, so that the controller can respond to the changes in time:

  • GitHub Repository: github.com/kubernetes/…

About the Client-Go Combat series

“Client-go Actual Combat” series is the original actual combat theme launched by Hsin Chen. It aims to experience client-Go related technologies with people by hand. From simple practice, we can gradually understand the powerful functions of Client-Go, and lay a solid foundation for subsequent operator learning.

Important premise

  • Before you start practicing client-Go, know the following:
  1. Kubernetes basic principles and operations;
  2. Kubernetes Group, Version, Resource, kubernetes Group, Version, Resource

This paper gives an overview of

As the beginning of the series, in addition to the introduction to client-Go, the following preparations should be made for the actual combat:

  1. List the hardware to be used;
  2. List the software to be used and its version;
  3. Synchronize kubernetes configuration files so that the development environment can access Kubernetes remotely;

Environmental information

  • As shown in the figure below, two computers were used in this actual practice:

  1. Linux PC: The operating system is CentOS 7.9, kubernetes 1.20.0 has been installed
  2. MacBook Pro: The operating system is macOS Big Sur(11.1) and the coding is done on this computer
  3. Version 1.15.7 is installed on the MacBook Pro
  4. You can choose your IDE according to your personal habits; I’m using goland-2020.2

Determine the client-Go version to use

Kubernetes: Kubernetes: Kubernetes: Kubernetes: Kubernetes

Kubernetes 1.15 Kubernetes 1.16 Kubernetes 1.17 Kubernetes 1.18 Kubernetes 1.19 Kubernetes 1.20
Kubernetes - 1.15.0 +- +- +- +- +-
Kubernetes - 1.16.0 +- +- +- +- +-
Kubernetes - 1.17.0/v0.17.0 +- +- +- +- +-
Kubernetes - 1.18.0/v0.18.0 +- +- +- +- +-
Kubernetes - 1.19.0/v0.19.0 +- +- +- +- +-
Kubernetes - 1.20.0/v0.20.0 +- +- +- +- +-
HEAD +- +- +- +- +- +-

The ✓, + and – in the grid are explained here:

  • V0.20.0 can match kubernetes version 1.20.0 exactly.

  • +Some new features are supported by client-Go, but not by kubernetes.
  • -Kubernetes supports some new features, but this client-go version does not.
  • I here kubernetes version is 1.20.0, so client-Go version 0.20.0 is the most suitable;

Copy the configuration file for the K8S environment

  • To enable go applications on MacBook Pro computers to access K8S, install the/.kube/configCopy the files to the /.kube/ directory on your MacBook Pro;

Description of client objects

  • Kubernetes API Server can be used to interact with the client objects provided by Client-Go. Client-go provides the following four client objects, which will be experienced one by one:
  1. RESTClient: This is the most basic client object, only to HTTPRequest encapsulation, RESTFul API, the use of this object is not convenient, because many parameters have to be set by the user, so client-Go based on RESTClient and three new client object;
  2. ClientSet: A Resource is a client, and multiple resources are corresponding to multiple clients. Therefore, a ClientSet is a collection of multiple clients, which is easy to understand.
  3. DynamicClient: allows you to access built-in resources and custom resources, which is similar to a Java collection operation. If the content is of type Object, you can perform a cast based on the actual situation.
  4. DiscoveryClient: used to discover the Group, Version, Resources and other information supported by kubernetes API Server.
  • Now that our environment and knowledge preparations are complete, let’s explore the powerful client-Go!

You are not alone, Xinchen original accompany all the way

  1. Java series
  2. Spring series
  3. The Docker series
  4. Kubernetes series
  5. Database + middleware series
  6. The conversation series

Welcome to pay attention to the public number: programmer Xin Chen

Wechat search “programmer Xin Chen”, I am Xin Chen, looking forward to enjoying the Java world with you…

Github.com/zq2599/blog…