Please help finish below exercise and publish to your github account, update to me when u finish, then I will pull and follow your document to verify. The target date will be next Friday, good luck.
- Develop a CRD controller to create/update/delete a gin based http service which has /health with actions GET and PUT supported, json payload.
- By default, a new created resource which will only enable /health action GET.
- But the CRD has ability to support to update existing resource to enable or disable /heath actions.
- Unit test is necessary.
- If have time, take a look istio gateway to think about how to integrate into your CRD to expose your gin http service to outside.
Please provide the readme to describe the design and tutorial about how to execute supported cases.
- Run CRD Controller
cd <SRC_ROOT>/go_hello_crd_controller/cmd/crd-controller
go run crud.go
- Run CRD Controller test
cd <SRC_ROOT>/go_hello_crd_controller/cmd/crd-controller
go test
- Build Docker
- Use command "docker-compose up" to bring up the docker
- Open browser on "http://localhost:5000/api/v1/resources" to get list of current resources
- Use command "docker-compose down" to bring down the docker
- Setup Minikube or kubernetes on docker for desktop
- Deploy pod and service
Using kubernetes:
docker pull cclhsu/go_hello_crd_controller:latest
cd <SRC_ROOT>/go_hello_crd_controller/cmd/crd-controller/k8s
kubectl create -f go-hello-crd-controller-deployment.yaml
kubectl create -f go-hello-crd-controller-service.yaml
Using istio:
docker pull cclhsu/go_hello_crd_controller:latest
cd <SRC_ROOT>
istioctl kube-inject -f go-hello-crd-controller-istio-spec.yaml | kubectl apply -f -
- Check if deployments and services is working process
Using kubernetes:
kubectl describe deployment go-hello-crd-controller
kubectl get deployments
kubectl get pods
kubectl get services
Using istio:
kubectl get gateways
kubectl get virtualservices
# kubectl get service -n istio-system
kubectl get service istio-ingressgateway -n istio-system
kubectl get service istio-egressgateway -n istio-system
- Check for the exposed port "5000:30549/TCP". Externally, we will access 30549.
15004921clarkhsu:k8s clark_hsu$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
go-hello-crd-controller NodePort 10.98.129.171 <none> 5000:30549/TCP 8s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 34m
http://localhost:30549/api/v1/resources
- Delete pod and service
Using kubernetes:
kubectl delete -f go-hello-crd-controller-service.yaml
kubectl delete -f go-hello-crd-controller-deployment.yaml
Using istio:
kubectl delete --ignore-not-found=true -f go-hello-crd-controller-istio-spec.yaml
Using Docker or K8S:
curl -i http://localhost:5000/api/v1/resources
Using ISTIO:
curl -i http://localhost/api/v1/resources
Using Docker or K8S:
curl -i http://localhost:5000/api/v1/resources/1
Using ISTIO:
curl -i http://localhost/api/v1/resources/1
Using Docker or K8S:
curl -i -X POST -H "Content-Type: application/json" -d "{\"name\":\"A\",\"enable\":false,\"state\":\"\"}" http://localhost:5000/api/v1/resources
Using ISTIO:
curl -i -X POST -H "Content-Type: application/json" -d "{\"name\":\"A\",\"enable\":false,\"state\":\"\"}" http://localhost/api/v1/resources
Using Docker or K8S:
curl -i -X PUT -H "Content-Type: application/json" -d "{\"name\":\"B\",\"enable\":false,\"state":\"\"}" http://localhost:5000/api/v1/resources/1
Using ISTIO:
curl -i -X PUT -H "Content-Type: application/json" -d "{\"name\":\"B\",\"enable\":false,\"state":\"\"}" http://localhost/api/v1/resources/1
Using Docker or K8S:
curl -i -X DELETE http://localhost:5000/api/v1/resources/1
Using ISTIO:
curl -i -X DELETE http://localhost/api/v1/resources/1
Using Docker or K8S:
curl -i http://localhost:5000/api/v1/resources/1/health
Using ISTIO:
curl -i http://localhost/api/v1/resources/1/health
Using Docker or K8S:
curl -i -X PUT -H "Content-Type: application/json" -d "{ \"name\":"A\",\"enable\":true,\"state\":"1\" }" http://localhost:5000/api/v1/resources/1
Using ISTIO:
curl -i -X PUT -H "Content-Type: application/json" -d "{ \"name\":"A\",\"enable\":true,\"state\":"1\" }" http://localhost/api/v1/resources/1