Last active
February 10, 2024 00:23
-
-
Save mtcoffee/362fce4980da6571b43cce3a0a2359fc to your computer and use it in GitHub Desktop.
nginx on K3s with traefik ingress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kubectl create -f - <<EOF | |
--- | |
apiVersion: v1 | |
kind: Namespace | |
metadata: | |
name: nginxweb | |
labels: | |
name: nginx | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: nginx | |
namespace: nginxweb | |
labels: | |
app: nginx | |
spec: | |
replicas: 1 | |
selector: | |
matchLabels: | |
app: nginx | |
template: | |
metadata: | |
labels: | |
app: nginx | |
spec: | |
containers: | |
- name: nginx | |
image: nginx:alpine | |
imagePullPolicy: Always | |
ports: | |
- containerPort: 80 | |
--- | |
kind: Service | |
apiVersion: v1 | |
metadata: | |
name: nginx-service | |
namespace: nginxweb | |
spec: | |
ports: | |
- name: nginx-service-port | |
port: 80 | |
protocol: TCP | |
targetPort: 80 | |
selector: | |
app: nginx | |
--- | |
apiVersion: traefik.containo.us/v1alpha1 | |
kind: Middleware | |
metadata: | |
name: mw-admin | |
namespace: nginxweb | |
spec: | |
stripPrefix: | |
forceSlash: false | |
prefixes: | |
- /web | |
--- | |
apiVersion: networking.k8s.io/v1 | |
kind: Ingress | |
metadata: | |
name: nginx-ingress | |
namespace: nginxweb | |
annotations: | |
kubernetes.io/ingress.class: traefik | |
traefik.ingress.kubernetes.io/router.middlewares: nginxweb-mw-admin@kubernetescrd | |
spec: | |
ingressClassName: traefik # can be left blank if a default exists | |
rules: | |
- host: # define the hostname if needed | |
http: | |
paths: | |
- path: /web | |
pathType: Prefix | |
backend: | |
service: | |
name: nginx-service | |
port: | |
number: 80 | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment