Play with kubernetes controller
Concept ¶
Kubernetes Components
Article - Kubernetes Operators 101
Framework for building Kubernetes APIs
Go clients for talking to a kubernetes cluster
Steps ¶
- Login cluster
wbx3op-sjctmp01in cloudhfedev
1. Run the play-controller server locally (optional if already exists in cluster or held locally by someone else). -
Create a namespace with your
CEC_ID.```text kubectl create ns CEC_ID ``` -
Create a Secret on your namespace with following requirements:
1. Secret name is `workshop-secret`. 2. Secret data with `botToken`(base64 encoded): ```text TldVM05tVmlabVV0TUdSaFpDMDBPRFUxTFRreU0yUXRZek14WldZNE56QTJNREU0TW1VNVltRm1OelF0TmpWa19QRjg0XzFlYjY1ZmRmLTk2NDMtNDE3Zi05OTc0LWFkNzJjYWUwZTEwZg== ``` 3. Secret data with `roomId`(base64 encoded): ```text WTJselkyOXpjR0Z5YXpvdkwzVnpMMUpQVDAwdk56WTJNRGMwWVRBdE56Vm1ZUzB4TVdWa0xXRTNPREV0WmpjNU16TTJOamhsTW1GbQ== ``` Hints: ```yaml apiVersion: v1 data: botToken: XXXX roomId: XXXX kind: Secret metadata: name: workshop-secret namespace: XXXX type: Opaque ``` ```text kubectl apply -f xxxx -n CEC_ID ``` -
Create a CR based on below CRD on your namespace (No need to apply CRD in cluster if already exists).
apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.11.1 creationTimestamp: null name: plays.workshop.crd.play.controller.io spec: group: workshop.crd.play.controller.io names: kind: Play listKind: PlayList plural: plays singular: play scope: Namespaced versions: - name: v1 schema: openAPIV3Schema: description: Play is the Schema for the plays API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' type: string kind: description: 'Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' type: string metadata: type: object spec: description: PlaySpec defines the desired state of Play properties: who: description: Who is a field of Play. Edit play_types.go to remove/update type: string type: object status: description: PlayStatus defines the observed state of Play type: object type: object served: true storage: true subresources: status: {}Hints:
apiVersion: workshop.crd.play.controller.io/v1 kind: Play metadata: name: play-sample namespace: XXXX spec: who: "Ted Zhao"kubectl apply -f xxxx -n CEC_ID -
After you create or update the CR in cluster
wbx3op-sjctmp01, the bot will send a message in the room, according to thebotTokenandroomIdin Secret yaml.
Code ¶
see Monitoring/play-controller on GitHub