Skip to content
This repository was archived by the owner on Mar 26, 2024. It is now read-only.

Commit bfd1be0

Browse files
committed
build: step2
issue #2
1 parent 8902afa commit bfd1be0

File tree

10 files changed

+261
-3429
lines changed

10 files changed

+261
-3429
lines changed

.doc/5-tutorial.md

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/
77
```shell
88
mkdir -p $HOME/Developer/custom-kubernetes-controller
99
cd $HOME/Developer/custom-kubernetes-controller
10-
# we'll use a domain of smhmayboudi.github.io
11-
# so all API groups will be <group>.smhmayboudi.github.io
12-
operator-sdk init --domain=smhmayboudi.github.io --repo=github.com/smhmayboudi/custom-kubernetes-controller
10+
# we'll use a domain of interview.com
11+
# so all API groups will be <group>.interview.com
12+
operator-sdk init --domain interview.com --repo github.com/smhmayboudi/custom-kubernetes-controller
1313
```
1414

1515
### MacOS
@@ -19,9 +19,9 @@ https://kubebuilder.io/plugins/available-plugins
1919
```shell
2020
mkdir -p $HOME/Developer/custom-kubernetes-controller
2121
cd $HOME/Developer/custom-kubernetes-controller
22-
# we'll use a domain of smhmayboudi.github.io
23-
# so all API groups will be <group>.smhmayboudi.github.io
24-
operator-sdk init --domain=smhmayboudi.github.io --repo=github.com/smhmayboudi/custom-kubernetes-controller --plugins=go/v4
22+
# we'll use a domain of interview.com
23+
# so all API groups will be <group>.interview.com
24+
operator-sdk init --domain interview.com --repo github.com/smhmayboudi/custom-kubernetes-controller --plugins go/v4
2525
```
2626

2727
## Manager
@@ -80,6 +80,79 @@ The above example will change the scope of your project to a single Namespace. I
8080

8181
Also, it is possible to use the [DefaultNamespaces](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Options) from cache.Options{} to cache objects in a specific set of namespaces. For further information see [cache.Options{}](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/cache#Options)
8282

83+
## Create a new API and Controller
84+
85+
[Deploy Image plugin](https://book.kubebuilder.io/plugins/deploy-image-plugin-v1-alpha.html)
86+
[Single Group to Multi-Group](https://book.kubebuilder.io/migration/multi-group.html)
87+
[Understanding Kubernetes APIs](https://book.kubebuilder.io/cronjob-tutorial/gvks.html)
88+
[Controller Runtime](https://github.com/kubernetes-sigs/controller-runtime)
89+
90+
```shell
91+
operator-sdk create api --group cache --version v1alpha1 --kind Memcached --resource --controller
92+
# OR
93+
operator-sdk create api --group cache --version v1alpha1 --kind Memcached --plugins "deploy-image/v1-alpha" --image=kind-registry:5000/library/memcached:1.6.23-alpine3.19 --image-container-command="memcached,-m=64,-o,modern,-v" --run-as-user="1001"
94+
```
95+
96+
In general, it’s recommended to have one controller responsible for managing each API created for the project to properly follow the design goals set by [controller-runtime](https://github.com/kubernetes-sigs/controller-runtime).
97+
98+
## Define the API
99+
100+
modify memcached_types
101+
102+
```shell
103+
make generate
104+
```
105+
106+
## Generating CRD manifests
107+
108+
```shell
109+
make manifests
110+
```
111+
112+
## Docker
113+
114+
```shell
115+
./.script/kind-with-registry.sh
116+
```
117+
83118
```shell
84-
operator-sdk create api --group=cache --version=v1alpha1 --kind=Memcached --resource --controller
119+
docker tag memcached:1.6.23-alpine3.19 localhost:5001/library/memcached:1.6.23-alpine3.19
120+
docker push localhost:5001/library/memcached:1.6.23-alpine3.19
85121
```
122+
123+
```shell
124+
make docker-build docker-push IMG=localhost:5001/library/controller:latest
125+
# OR
126+
make docker-build docker-push
127+
docker tag controller:latest localhost:5001/library/controller:latest
128+
docker push localhost:5001/library/controller:latest
129+
```
130+
131+
## Run the Operator
132+
133+
### Run locally outside the cluster
134+
135+
```shell
136+
make install run MEMCACHED_IMAGE="memcached:1.6.23-alpine3.19"
137+
```
138+
139+
```shell
140+
export
141+
make deploy IMG=kind-registry:5000/library/controller:latest
142+
```
143+
144+
```shell
145+
kubectl -n custom-kubernetes-controller-system get deployment
146+
kubectl -n custom-kubernetes-controller-system describe deployment/custom-kubernetes-controller-controller-manager
147+
kubectl -n custom-kubernetes-controller-system describe pod custom-kubernetes-controller-controller-manager
148+
kubectl -n custom-kubernetes-controller-system logs deployment/custom-kubernetes-controller-controller-manager
149+
150+
kubectl get pods --all-namespaces
151+
kubectl get deployments --all-namespaces
152+
kubectl get services --all-namespaces
153+
```
154+
155+
```shell
156+
kubectl delete namespace custom-kubernetes-controller-system
157+
```
158+

0 commit comments

Comments
 (0)