Develop Environment

Kind

kind is a tool for running local Kubernetes clusters using Docker container “nodes”. kind was primarily designed for testing Kubernetes itself but may be used for local development or CI.

1kind load docker-image --name <kind-cluster-name> --nodes <node-name> <image-name>:latest 

Certmangaer

1helm repo add jetstack https://charts.jetstack.io
2helm repo update
3helm install \
4  cert-manager jetstack/cert-manager \
5  --namespace cert-manager \
6  --create-namespace \
7  --version v1.10.1 \
8  --set installCRDs=true

Question

  1. K8s 的manifest 是如何生成的
  2. 代码的架构
  3. controller-gen的作用,如何根据对应的tag生成 k8smanifest
  4. clientgo 中的client set
  5. GVK和GVR
  6. 每一个controller 是如何注册到主程序中的
  7. 常用的依赖,core? controller runtime
  8. 应用部署的时候,首先创建crd资源以及role 权限,然后部署应用

k8s finalizaer

  1. Reconcile 函数什么时候回被调用到,
  2. Reconcile函数的返回值中如果含有err如何处理,err 为nil的时候如何处理
  3. Renconcile Result 什么情况下需要requeue,

Yaml 中的apiVersion

pod

deployment

Code中的struct defination

k8s.io/apimachinery/pkg/apis/meta/v1

ResourceList

Unstructured

golang 的type assert

Scheme: resource register

新增一个crd的时候需要注册到scheme

UnversionedType: metav1.Status, metav1.APIVersions, metav1.APIGroupList, metav1.APIGroup, metav1.APIResourceList

KnownType: Pod

AddKnowTypes? or Add UnversionedTypes

 1// k8s.io/apimachniery/pkg/runtime/scheme.go
 2type Scheme struct {
 3	// gvkToType allows one to figure out the go type of an object with
 4	// the given version and name.
 5	gvkToType map[schema.GroupVersionKind]reflect.Type
 6
 7	// typeToGVK allows one to find metadata for a given go object.
 8	// The reflect.Type we index by should *not* be a pointer.
 9	typeToGVK map[reflect.Type][]schema.GroupVersionKind
10  //....
11}

Codec

Serializer:

Codec: Serializer is one kind of Codec

What is protobuf, wirte a demo

Converter: resource Version convert

Kubectl

1kubectl run pod --image=nginx:latest # create one or more pod
2
3kubectl expose
4
5
6kubectl rolling-update # uses replication controller roll update
7
8kubectl cluster-info
9kubectl top

Cobra

Informer machanism

WorkQueue

Golang的优雅退出

K8s 代码生成器

tags

  • Package Tag
  • Type Tag
1//+k8s:deepcopy-gen=package
2//+groupName=example.com
3
4// Local Tag
5// +genclient