Skip to content

Commit

Permalink
feat: Enable ingress (#4)
Browse files Browse the repository at this point in the history
* fix: Move targetPort to a variable
* feat: loop over hosts
* feat: Enabled ingress
* chore: Clean up the default namespace in README.md
  • Loading branch information
benniemosher authored Jan 8, 2025
1 parent 23323e4 commit b6b3e4d
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
3 changes: 0 additions & 3 deletions .ansible-lint

This file was deleted.

4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 12 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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@<SERVER_IP>:/etc/rancher/k3s/k3s.yaml ~/k3s.yaml
sed -i '' 's/127.0.0.1/<SERVER_IP>/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 <pod-name> -n default
kubectl describe deployment hello-world
kubectl describe pod <pod-name>
```

### Deploy helm charts
Expand All @@ -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
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion hello-world/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 3 additions & 3 deletions hello-world/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
40 changes: 23 additions & 17 deletions hello-world/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
8 changes: 5 additions & 3 deletions hello-world/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b6b3e4d

Please sign in to comment.