diff --git a/Makefile b/Makefile index 2e070d6..9b10bde 100644 --- a/Makefile +++ b/Makefile @@ -53,14 +53,18 @@ run: ## Run the service ##@ Kubernetes .PHONY: cluster +# k3d cluster create --agents 1 --registry-create cluster-registry:0.0.0.0:32000 --port '8080:80@loadbalancer' cluster: ## Create a K3D Kubernetes cluster with load balancer and registry $(info Creating Kubernetes cluster with a registry and 1 node...) - k3d cluster create --agents 1 --registry-create cluster-registry:0.0.0.0:32000 --port '8080:80@loadbalancer' + docker container run -d --name registry.local -v local_registry:/var/lib/registry --restart always -p 5000:5000 registry:2 + k3d cluster create --config k3d-config.yaml + docker network connect k3d-k3s-default registry.local .PHONY: cluster-rm cluster-rm: ## Remove a K3D Kubernetes cluster $(info Removing Kubernetes cluster...) k3d cluster delete + docker stop registry.local && docker rm registry.local .PHONY: login login: ## Login to IBM Cloud using yur api key diff --git a/README.md b/README.md index e5243cd..219deb8 100644 --- a/README.md +++ b/README.md @@ -44,3 +44,22 @@ kubectl -n default get secret all-icr-io -o yaml | sed 's/default/dev/g' | kubec What the second command does is to get the `ImagePullSecret` named `all-icr-io` from the `default` namespace and running it through `sed` to change the `namespace:` to whatever is needed, and applying it to the `dev` namespace. +### Use with Minikube + +In order to use Minikube you need to enable the ingress and registry addons. + +Here are the commands to get `minikube` working: + +```bash +minikube start +minikube addons enable ingress +minikube addons enable registry +``` + +You can also specify these are start up with: + +```bash +minikube start --addons ingress --addons registry +``` + +See Minikube [documentation](https://minikube.sigs.k8s.io/docs/start/) for reference. diff --git a/deploy/deployment.yaml b/deploy/deployment.yaml index 9587032..a40274b 100644 --- a/deploy/deployment.yaml +++ b/deploy/deployment.yaml @@ -22,7 +22,7 @@ spec: restartPolicy: Always containers: - name: hitcounter - image: cluster-registry:32000/hitcounter:1.0 + image: registry.local:5000/hitcounter:1.0 imagePullPolicy: IfNotPresent ports: - containerPort: 8080 @@ -34,3 +34,9 @@ spec: name: redis-creds key: uri resources: + limits: + cpu: "0.25" + memory: "64Mi" + requests: + cpu: "0.10" + memory: "32Mi" diff --git a/deploy/pv.yaml b/deploy/pv.yaml new file mode 100644 index 0000000..6a92f65 --- /dev/null +++ b/deploy/pv.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: pv0001 +spec: + capacity: + storage: 1Gi + accessModes: + - ReadWriteMany + hostPath: + path: /data/pv0001 + storageClassName: "" diff --git a/deploy/redis.yaml b/deploy/redis.yaml index 7e99e4a..d52a854 100644 --- a/deploy/redis.yaml +++ b/deploy/redis.yaml @@ -25,16 +25,31 @@ spec: volumeMounts: - name: redis-storage mountPath: /data - # resources: - # limits: - # cpu: "0.25" - # memory: "64Mi" - # requests: - # cpu: "0.10" - # memory: "32Mi" + resources: + limits: + cpu: "0.50" + memory: "64Mi" + requests: + cpu: "0.25" + memory: "32Mi" volumes: - name: redis-storage - emptyDir: {} + persistentVolumeClaim: + claimName: redis-data + # emptyDir: {} + +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: redis-data +spec: + accessModes: + - ReadWriteMany + resources: + requests: + storage: 1Gi + storageClassName: "" --- apiVersion: v1 diff --git a/k3d-config.yaml b/k3d-config.yaml new file mode 100644 index 0000000..0156a9d --- /dev/null +++ b/k3d-config.yaml @@ -0,0 +1,17 @@ +# k3d cluster create --agents 1 --registry-create cluster-registry:0.0.0.0:32000 --port '8080:80@loadbalancer' +--- +apiVersion: k3d.io/v1alpha5 +kind: Simple +# name: devops +servers: 1 +agents: 1 +ports: +- port: 8080:80 + nodeFilters: + - loadbalancer +registries: + config: | + mirrors: + "registry.local:5000": + endpoint: + - http://registry.local:5000 diff --git a/requirements.txt b/requirements.txt index 1ee5fe6..8243705 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,4 +21,4 @@ green==3.4.3 coverage==7.1.0 # Utilities -httpie==3.2.1 +httpie==3.2.2 diff --git a/skaffold.yaml b/skaffold.yaml new file mode 100644 index 0000000..0ae392b --- /dev/null +++ b/skaffold.yaml @@ -0,0 +1,20 @@ +apiVersion: skaffold/v4beta6 +kind: Config +metadata: + name: hitcounter +build: + artifacts: + - image: registry.local:5000/hitcounter + docker: + dockerfile: Dockerfile +test: + - context: . + image: hitcounter + custom: + - command: DATABASE_URI=redis://localhost:6379/0 green +manifests: + rawYaml: + - deploy/** + # kustomize: + # paths: + # - "kubernetes/dev"