|
1 | 1 |
|
2 | 2 |
|
3 |
| -# Kluster (In Progress) |
| 3 | +# Kluster |
4 | 4 |
|
5 |
| -An operator that we are writing in the YouTube channel (https://youtu.be/89PdRvRUcPU) |
| 5 | +A example Kubernetes operator to create Kubernetes cluster on DigitalOcean. |
| 6 | +Once the operator is running, and we create a Kluster K8S resource in a cluster, a DigitalOcean Kubernetes |
| 7 | +cluster would be created with provided configuration. |
6 | 8 |
|
7 |
| -viveksingh.dev |
8 |
| -v1alpha1 |
| 9 | +This operator was written as part of one of my [YouTube playlist](https://www.youtube.com/watch?v=89PdRvRUcPU&list=PLh4KH3LtJvRTtFWz1WGlyDa7cKjj2Sns0). |
9 | 10 |
|
10 |
| -generate |
| 11 | +Here is an example of the Kluster resource |
11 | 12 |
|
12 |
| -1. deep copy objects |
13 |
| -2. clientset |
14 |
| -3. informers |
15 |
| -4. lister |
16 |
| - |
17 |
| -# Commands that we used |
| 13 | +``` |
| 14 | +apiVersion: viveksingh.dev/v1alpha1 |
| 15 | +kind: Kluster |
| 16 | +metadata: |
| 17 | + name: kluster-0 |
| 18 | +spec: |
| 19 | + name: kluster-0 |
| 20 | + region: "nyc1" |
| 21 | + version: "1.21.3-do.0" |
| 22 | + tokenSecret: "default/dosecret" # secret that has DigitalOcean token |
| 23 | + nodePools: |
| 24 | + - count: 3 |
| 25 | + name: "dummy-nodepool" |
| 26 | + size: "s-2vcpu-2gb" |
| 27 | +``` |
18 | 28 |
|
19 |
| -Should be run from root dir of project. |
| 29 | +# Deploy on a Kubernetes cluster |
20 | 30 |
|
21 |
| -## Code generator |
| 31 | +Execute below command, from root of the repo |
22 | 32 |
|
23 |
| -Make sure you have installed code generator |
| 33 | +Create Kluster CRD |
24 | 34 |
|
25 | 35 | ```
|
26 |
| -execDir=~/go/src/k8s.io/code-generator |
27 |
| -"${execDir}"/generate-groups.sh all github.com/viveksinghggits/kluster/pkg/client github.com/viveksinghggits/kluster/pkg/apis viveksingh.dev:v1alpha1 --go-header-file "${execDir}"/hack/boilerplate.go.txt |
| 36 | +kubectl create -f manifests/viveksingh.dev_klusters.yaml |
28 | 37 | ```
|
29 | 38 |
|
30 |
| -## CRDs |
| 39 | +Create RBAC resources and deployment |
31 | 40 |
|
32 | 41 | ```
|
33 |
| -controller-gen paths=github.com/viveksinghggits/kluster/pkg/apis/viveksingh.dev/v1alpha1 crd:trivialVersions=true crd:crdVersions=v1 output:crd:artifacts:config=manifests |
| 42 | +kubectl create -f manifests/install/ |
34 | 43 | ```
|
35 | 44 |
|
| 45 | +# Create a secret with DigitalOcean token |
36 | 46 |
|
| 47 | +To call DigitalOcean APIs we will have to create a secret with DigitalOcean token that |
| 48 | +will be used in the Kluster CR that we create. |
37 | 49 |
|
| 50 | +``` |
| 51 | +kubectl create secret generic dosecret --from-literal token=<your-DO-token> |
| 52 | +``` |
38 | 53 |
|
39 |
| -apiVersion |
40 |
| -kind |
41 |
| -metadata: |
42 |
| -spec: |
43 |
| - ... |
44 |
| - ... |
45 |
| -status: |
46 |
| - clusterId |
47 |
| - progress |
48 |
| - kubeconfig |
49 |
| - |
50 |
| - |
51 |
| - |
52 |
| -role-test: |
53 |
| - resources: Kluster/status |
54 |
| - |
55 |
| -resource |
56 |
| - apis/apps/v1/namespaces/<ns>/deployments |
57 |
| - v1/namespaces/<ns>/pods/<podname>/ |
58 |
| - |
59 |
| - |
60 |
| -pods logs |
61 |
| - |
62 |
| -logs subresources |
63 |
| - v1/namespaces/<ns>/pods/<podname>/logs |
64 |
| - |
| 54 | +# Create a kluster CR |
65 | 55 |
|
| 56 | +Create the kluster resource to create a k8s cluster in DigitalOcean |
66 | 57 |
|
| 58 | +``` |
| 59 | +kubectl create -f manifests/klusterone.yaml |
| 60 | +``` |
0 commit comments