Kubernetes ???? ???? ?? ???? ??? KubeBuilder? Controller-Runtime? ???? ? ???? ????. 1. ??? ?? ?? : CRD? ?? ??? ?? ???? ???? ????? ???? ?? ??? ?? ?? ??? ???? ?? ?? ??? ??????. 2. KubeBuilder? ????? ????? API? ???? CRD, ???? ? ?? ??? ???? ??????. 3. CRD? ?? ? ?? ??? API/V1/MYAPP_TYPES.GO?? ???? CRD YAML? ???? ?? ?????. 4. ????? ?? ???? ???? ??? ???? R.Create, R.Update ? ?? ??? ???? Kubernetes ???? ??????. 5. GO ??? ?? RBAC ??? ???? Make Manifests? ???? ???? ???? Docker-Build? ??? Kubectl? ?? ????? ??????. 6. ?? ??? ????? : ?? IDEMPOTENCE? ??? ????, ??? ????? ????, ???? ???? ?? ? ???? ???? ??? ?? ???? ? ? ??? ?????. 7. ?? ???? ?? ? ??? ???? ?? ????? fakeclient? ??????. ????? ??? ??? ??? CRD? ????, ??? ??? ????, ????-???? ???? K8S ?? ??? ?????, ??? ?? ??? ?? ??? ??? ? ???? ????.
GO? Kubernetes ???? ???? ?? ??? ??? ?? ????? ???? ?? Kubernetes ?? ???? ???? ?? ???? ?? ? ?????. ???? CRS (Custom Resources) ? ????? ???? ??, ????, ????? ? ?? ??? ?? ?? ???? ?? ? ??? ??????. Kubernetes ??? GO? ?????? Client-Go ? Controller Runtime? ?? ???? ???? ????? ?? ??? Go? ????? ?????.

??? ?? ?? ??? ???? ???? ? ????? ???? ??????.
1. ??? ??? ??????
???? CRD (Custom Resource Definition)? ?? ???? ?? ??? ???? ??? ??? ?? ???? ??? ???? ??? ??? ???? ? ?????.

- CR (Custom Resource) : ?? ????? ??? ?? (? :
MyAppDatabase
)? ???? YAML ?????. - ???? :
MyAppDatabase
????? Kubernetes ??? (? : Statefulsets, Services)? ???? ??? ?? GO ????.
?? ??? ?? ? ?? ??? ???????.
2. KubeBuilder ? ???? ???? ??????
GO?? ???? ???? ?? ?? ??? Kubernetes SIG? ??? KubeBuilder? ???? ????. Kubernetes SIGS? ??? ????? ??, ??? ?? ? ??? ?? ??? ?? ??? ???? ???? ???? ???? ????? ?????.

?? ?? :
# KubeBuilder? ?????? curl -l -o https://go.kubebuilder.io/dl/latest/$(go env goos)/$ (go env goarch) tar -xzf kubebuilder _*_ $ (go env goos) _ $ (go env goarch) .tar.gz Sudo MV KubeBuilder _*_ $ (GO ENV GOOS) _ $ (GO ENV GOARCH)/USR/LOCAL/KUBEBUILDER ???? ?? = $ ?? :/usr/local/kubebuilder/bin
? ???? ??? :
mkdir myapp-operator CD MyApp-operator KubeBuilder init--domain example.com-repo example.com/myapp-operator KubeBuilder ?? API -?? ? -Version v1 --kind myapp
??? ??? ?????.
-
api/v1/myapp_types.go
- CRD ???? ??????. -
controllers/myapp_controller.go
- ?? ??? ???? ?. -
config/
- kustomize? CRD ? RBAC ????? ????????.
3. ??? ?? ???? ??????
api/v1/myapp_types.go
?? :
myAppSpec struct {? ??????. ?? int32`json : "Replicas"` ??? ???`json : "???"` ?? int32` json : "??"` } myappstatus struct? ?????? { ReadyRelycas int32` json : "ReadyRelycas"` ?? [] metav1.condition`json : "??, ??"` }
??? GO ???? CRD YAML? ???? ?? make manifests
.
4. ?? ??? ??????
controllers/myapp_controller.go
?? MyApp ???? ?? ? ??? Reconcile
???? ?????.
func (r *myEctReconciler) ?? (ctx context.context, req ctrl.request) (ctrl.result, error) { log : = r.log.withValues ( "myApp", req.namespacedName) var myapp myapp err : = r.get (ctx, req.namespacedname, & myapp); err! = nil { ctrl.result {}, client.ignorenotfound (err)? ?????. } // ??? ????? ?????? destireddep : = & appsv1.deployment { Objectmeta : metav1.objectmeta { ?? : myapp.name, ?? ???? : myapp.namespace, }, ?? : appsv1.deploymentspec { ??? : & myapp.spec.replicas, ??? : & metav1.labelselector { matchlabels : map [String] String { "app": myapp.name}, }, ??? : corev1.podtemplatespec { Objectmeta : metav1.objectmeta { ??? : map [string] string { "app": myapp.name}, }, ?? : corev1.podspec { ???? : [] Corev1.Container { { ?? : "?", ??? : myapp.spec.image, ?? : [] corev1.containerport {{containerport : myapp.spec.port}}, }, }, }, }, }, } // Controller-Runtime? ?????? ???? ???? ???????? err : = r.create (ctx, destireddep); err! = nil { if! errors.isalreadyExists (err) { ctrl.result {}, err } } // ???? ?? myapp.status.readyReplicas = 0 // ?? ???? ???? err : = r.status (). update (ctx, & myapp); err! = nil { ctrl.result {}, err } ctrl.result {}, nil? ????? }
r.Create
, r.Update
, r.Patch
?? r.Delete
???? ??? ??????.
5. RBAC? ???? ??????
KubeBuilder? GO ??? ???? RBAC ??? ?????.
// kubeBuilder : rbac : groups = apps.example.com, resources = myApps, ?? = ?? = get; list; watch; create; update; patch; delete // kubeBuilder : rbac : groups = apps, resources = ??, ?? = get; list; watch; create; update; patch; delete // kubeBuilder : rbac : groups = core, resources = pods, ?? = list
???:
?????? Docker-Build IMG = MyApp-operator : v0.0.1? ????? kubectl apply -f config/crd/bases/apps.example.com_myapps.yaml kubectl ?? MyApp-operator -Image = myapp-operator : v0.0.1? ????
?? make deploy IMG=myapp-operator:v0.0.1
?? kustomize ??? ???? ?? ??????.
6. ?? ??
- Idempotency : ?? ??? ?? ? ??? ? ????. ?? ??? ????? ?????.
- ?? ?? : ??? ??? ?????. ??? ??? ??
ctrl.Result{RequeueAfter: time.Second}
??????. - ?? ? ??? :
r.Log
?r.Recorder.Event()
???? Kubernetes ???? ?????. - Finalizers : CR? ???? ?? ??? ???? ? ? ??????.
- WebHooks :
kubebuilder create webhook
??????.
7. ???
- ETCD? Kube-Apiserver? ??? ???? ?? ?????
envtest
??????. -
fakeclient
???? ?? ??? ?? ?? ???? ??????.
?? ??? ?? :
?? (??) "sigs.k8s.io/controller-runtime/pkg/envtest" )) var testenv *envtest.environment
????? Go? Kubernetes ???? ?????.
-
kubebuilder
? CRD ?? - ??? ??? ?? ??? ???? ????? ?????
- Kubernetes ?? ??? ???? ??
controller-runtime
????? -
envtest
? ????? ?? ?????? ?????
??? ?? ???? ??? ?? ??????. KubeBuilder? Controller Runtime? ???? ??? ???????. ?? ???? ? ??? ? ????? ???? ??????.
? ??? Kubernetes ??? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

KubernetEsoperator? ???? ?? ???? ??? KubeBuilder? Controller-Runtime? ???? ? ???? ????. 1. ??? ?? ?? : CRD? ?? ??? ?? ???? ???? ????? ???? ?? ??? ?? ?? ??? ???? ?? ?? ??? ??????. 2. KubeBuilder? ???? ????? ????? API? ???? CRD, ???? ? ?? ??? ???? ??????. 3. API/V1/MyApp_Types.go?? CRD? ?? ? ?? ??? ???? makemanifests? ???? Crdyaml? ?????. 4. ????? ??

GO?? ?? ?? ??? ??? ?? ?? ????? ??? ? ????. ? [t] struct {}? ???? ?? ?? ???? ? ??? ??? ?? ??? 0?? ??, ??, ?? ? ?? ??? ??? O (1) ?? ??????. ?? ????? ??? ??? ???? ?? Sync.rwmutex ?? Sync.Map? ?? ? ? ????. ??, ??? ??, ?? ?? ? ?? ????; ?? ?? ??? ????????? ??, ??, ??, ?? ? ?? ??? ????? ?? ????.

UselightWeightRouterSlikeChiforeFficiThtTphandlingWithBuitHbuilt-inmiddleWareAndContextSupport.2.LeverageGoroutinesandChannelSforConcurrency, AlwaysTempemwithContext.contextTopReventLeaks.3

usemulti-stagedockerbuildstocreatesmall, securebymingebinaryinaBuylderstageanderstageanderstageanderstageandeStageanminimimalimimalminimalimageMagelikealpinelinux, retingsizeAndattackSurface.2.optimizeBuildPerformanceByCopyinggo.modandGo.sumfirstoLockerAceArCachin

GO? ??? ??? ???/??? ? HTML/??? ???? ?? ??? ?? ??? ?? ??? ?????. ??? HTML/Template?? XSS ??? ?????? ?? ?? ??? ???? HTML? ?? ? ? ?? ???????. 1. {{{}} ??? ???? {{.fieldname}}? ?? ??, ??? ?? ? ??? ???? ?? ??? ????? ??? ??? ?????. 2. ???? ??, ???? ? ?? ?? GO ??? ??? ???? ??? ?? ?? ?? ??? ?????. 3. ?? ? ???? ??? ???? ???? ????? ?? ? ? ????. 4.ht

GO ? KAFKA ??? ??? ??? ??? ???? ?????? ???? ??????. ??? ????? ?????? ??? ?? ???????. 1. ??? GO ??? API? ??? ???? ??? ?? ?? Kafka-Go? ?? ??? ?????. ?? ??? ?????. 2. ?? ?? ?? ?? ??? ??? ?? Sarama? ??????. 3. ???? ??? ?? ??? ??? ??, ?? ??? ??? ??? ???? ????? ?? ?? ?? ? ??? ???????. 4. ???? ??? ??? ???? ?? ?? ?? ?? ??? ???? ???? ???? ???? ?? ??? ????? ???????. 5. ???? ?? JSON, AVRO ?? Protobuf? ???? SchemareGist? ???? ?? ????.

????? ?? ? ? ???? ???? ?? ??? ?? ???? ???? ?? ???? ??? ???? ?? ???? ???? ?? ??? ????? ??? ?? ?????. ??? ??? ?? ??? ?? ????? ??? ????. 1. ?? ??? ???? ??? ? ????? ?? ???? ?? ?? ??? ?? ???? ?? ???? ???? ???????. 2. ??? ??? ???? ???? ?? ????? ?? ??? ? ????. 3. Append? ??? ? ? ??? ??? ? ??? ?? ???? ???? ???? ? ????? ??? ?????????. ??? ?? ????? ???? ??? ????? ? ??? ????????.

govetcatchescommonlogicalErrorsandspuctructsingocodesuchas1) missuseofprintf-stylefunctionswithorrectarguments, 2) unkeyedstructliterals thatmayLeadiffieldAssignments, 3) senfingToclosedChannelswhichcaUsespanics, 4) inffectVeasment
