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

Commit e72f554

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

29 files changed

+942
-3428
lines changed

.doc/5-tutorial.md

Lines changed: 79 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,78 @@ 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+
118+
```shell
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
121+
```
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+
83155
```shell
84-
operator-sdk create api --group=cache --version=v1alpha1 --kind=Memcached --resource --controller
156+
kubectl delete namespace custom-kubernetes-controller-system
85157
```

.doc/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,48 @@
55
3. https://kubernetes.io/docs/concepts/extend-kubernetes/operator/
66
4. https://sdk.operatorframework.io/docs/installation/
77
5. https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/
8+
9+
# Run & Test & Clean
10+
11+
## Localy
12+
13+
```shell
14+
make install run
15+
16+
kubectl apply -f config/samples/
17+
18+
make uninstall
19+
make undeploy
20+
```
21+
22+
## Docker
23+
24+
```shell
25+
./.script/kind-with-registry.sh
26+
27+
# Docker Hub
28+
make docker-build docker-push IMG=smhmayboudi/custom-kubernetes-controller:latest
29+
make deploy IMG=smhmayboudi/custom-kubernetes-controller:latest
30+
31+
# Local Registry
32+
make docker-build docker-push IMG=localhost:5001/smhmayboudi/custom-kubernetes-controller:latest
33+
make deploy IMG=http://kind-registry:5000/smhmayboudi/custom-kubernetes-controller:latest
34+
35+
kubectl apply -f config/samples/
36+
37+
make uninstall
38+
make undeploy
39+
```
40+
41+
## OLM
42+
43+
```shell
44+
operator-sdk olm install
45+
make bundle IMG=smhmayboudi/custom-kubernetes-controller:v0.0.1
46+
make bundle-build bundle-push BUNDLE_IMG=smhmayboudi/custom-kubernetes-controller-bundle:v0.0.1
47+
operator-sdk run bundle smhmayboudi/custom-kubernetes-controller-bundle:v0.0.1
48+
49+
kubectl apply -f config/samples/
50+
51+
operator-sdk cleanup custom-kubernetes-controller
52+
```

0 commit comments

Comments
 (0)