From b6b3e4d0674361c01d23ea4ed67776ac2c936058 Mon Sep 17 00:00:00 2001 From: Bennie Mosher <337539+benniemosher@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:18:59 -0700 Subject: [PATCH] feat: Enable ingress (#4) * fix: Move targetPort to a variable * feat: loop over hosts * feat: Enabled ingress * chore: Clean up the default namespace in README.md --- .ansible-lint | 3 -- .pre-commit-config.yaml | 4 --- README.md | 25 ++++++++--------- hello-world/templates/NOTES.txt | 2 +- hello-world/templates/deployment.yaml | 6 ++-- hello-world/templates/ingress.yaml | 40 +++++++++++++++------------ hello-world/values.yaml | 8 ++++-- 7 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 .ansible-lint diff --git a/.ansible-lint b/.ansible-lint deleted file mode 100644 index b688aca..0000000 --- a/.ansible-lint +++ /dev/null @@ -1,3 +0,0 @@ ---- -exclude_paths: - - .github diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0f8d4df..d0bbdd9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,10 +23,6 @@ repos: rev: v1.35.1 hooks: - id: yamllint - - repo: https://github.com/ansible/ansible-lint - rev: v24.12.2 - hooks: - - id: ansible-lint - repo: https://github.com/markdownlint/markdownlint rev: v0.12.0 hooks: diff --git a/README.md b/README.md index abc33bd..e95ca54 100644 --- a/README.md +++ b/README.md @@ -33,18 +33,18 @@ Explore the charts, contribute, and streamline your Kubernetes deployments! 🤝 ### Setup kubeconfig ```bash -scp -i ~/.ssh/ansible_key ansible@192.168.202.14:/etc/rancher/k3s/k3s.yaml ~/k3s.yaml -sed -i '' 's/127.0.0.1/192.168.202.14/g' ~/k3s.yaml +scp -i ~/.ssh/ansible_key ansible@:/etc/rancher/k3s/k3s.yaml ~/k3s.yaml +sed -i '' 's/127.0.0.1//g' ~/k3s.yaml chmod 600 /Users/benniemosher/k3s.yaml export KUBECONFIG=~/k3s.yaml kubectl get nodes -kubectl get deployments --namespace default -kubectl get pods --namespace default -kubectl get services --namespace default +kubectl get deployments +kubectl get pods +kubectl get services ## More detailed queries -kubectl describe deployment hello-world -n default -kubectl describe pod -n default +kubectl describe deployment hello-world +kubectl describe pod ``` ### Deploy helm charts @@ -61,15 +61,14 @@ the chart if it is not already installed or upgrade it if it is already installed. ```bash -helm upgrade --install hello-world \ -./hello-world --namespace default +helm upgrade --install hello-world ./hello-world ``` After running the Helm upgrade command, you can verify that the deployment was successful by checking the status of the release: ```bash -helm status hello-world --namespace default +helm status hello-world ``` ### Troubleshoot cluster @@ -78,14 +77,14 @@ You can also use kubectl commands to check the status of the pods, services, and other resources: ```bash -kubectl get all -n default +kubectl get all ``` To delete the hello-world deployment: ```bash -kubectl delete deployment hello-world --namespace default -kubectl delete service hello-world --namespace default +kubectl delete deployment hello-world +kubectl delete service hello-world ``` To verify the deletion: diff --git a/hello-world/templates/NOTES.txt b/hello-world/templates/NOTES.txt index 5b2dda7..1b31cb3 100644 --- a/hello-world/templates/NOTES.txt +++ b/hello-world/templates/NOTES.txt @@ -1,7 +1,7 @@ {{- if .Values.ingress.enabled -}} 1. Get the application URL by running these commands: {{- range .Values.ingress.hosts }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ .host }}{{ range .paths }}{{ . }}{{ end }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ .host }}:{{ $.Values.service.nodePort }}{{ range .paths }}{{ . }}{{ end }} {{- end }} {{- else if eq .Values.service.type "LoadBalancer" -}} 1. Get the application URL by running these commands: diff --git a/hello-world/templates/deployment.yaml b/hello-world/templates/deployment.yaml index fbef9a5..9b3c5f8 100644 --- a/hello-world/templates/deployment.yaml +++ b/hello-world/templates/deployment.yaml @@ -26,12 +26,12 @@ spec: image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - - containerPort: 8080 + - containerPort: {{ .Values.service.targetPort }} livenessProbe: httpGet: path: / - port: 80 + port: {{ .Values.service.targetPort }} readinessProbe: httpGet: path: / - port: 80 + port: {{ .Values.service.targetPort }} diff --git a/hello-world/templates/ingress.yaml b/hello-world/templates/ingress.yaml index 175181c..8e2ccc1 100644 --- a/hello-world/templates/ingress.yaml +++ b/hello-world/templates/ingress.yaml @@ -1,29 +1,35 @@ --- -{{- if .Values.ingress.enabled -}} +{{- if .Values.ingress.enabled }} apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{- include "hello-world.fullname" . }} + name: {{ include "hello-world.fullname" . }} labels: - {{- include "hello-world.labels" . | nindent 4 }} + {{ include "hello-world.labels" . | nindent 4 }} annotations: - {{- toYaml .Values.ingress.annotations | nindent 4 }} + {{ toYaml .Values.ingress.annotations | nindent 4 }} spec: rules: - - host: {{ .Values.ingress.host }} - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: {{- include "hello-world.fullname" . }} - port: - number: {{ .Values.service.port }} + {{- range .Values.ingress.hosts }} + - host: {{ .host }} + http: + paths: + {{- range .paths }} + - path: {{ . }} + pathType: Prefix + backend: + service: + name: {{ include "hello-world.fullname" $ }} + port: + number: {{ $.Values.service.port }} + {{- end }} + {{- end }} {{- if .Values.ingress.tls }} tls: - - hosts: - - {{ .Values.ingress.host }} - secretName: {{ .Values.ingress.tlsSecret }} + - hosts: + {{- range .Values.ingress.hosts }} + - {{ .host }} + {{- end }} + secretName: {{ .Values.ingress.tlsSecret }} {{- end }} {{- end }} diff --git a/hello-world/values.yaml b/hello-world/values.yaml index b39834f..7e53217 100644 --- a/hello-world/values.yaml +++ b/hello-world/values.yaml @@ -11,14 +11,16 @@ service: type: NodePort port: 80 nodePort: 30001 + targetPort: 8080 ingress: - enabled: false + enabled: true annotations: - - nginx.ingress.kubernetes.io/rewrite-target: / + nginx.ingress.kubernetes.io/rewrite-target: "/" hosts: - host: mosher-labs.local - paths: [] + paths: + - / tls: [] autoscaling: