Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gukandrew/2541dd0e4b01b9d502d973d24d438d05 to your computer and use it in GitHub Desktop.
Save gukandrew/2541dd0e4b01b9d502d973d24d438d05 to your computer and use it in GitHub Desktop.
K3s Kubernetes deployment, service, and ingress configuration for hello-world app, serve app in container on 3000 port, exposed on Node 80 port
# kubectl apply -f k3s-hello-world-app-served-on-80-port-node.yaml
# kubectl delete -f k3s-hello-world-app-served-on-80-port-node.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world
labels:
app: hello-world
spec:
replicas: 1
selector:
matchLabels:
app: hello-world
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: hello-world
image: hashicorp/http-echo
args:
- "-text=Hello World"
- "-listen=:3000"
ports:
- containerPort: 3000
---
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
selector:
app: hello-world
ports:
- protocol: TCP
port: 3000
targetPort: 3000
type: ClusterIP
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-world-ingress
annotations:
# kubernetes.io/ingress.class: "traefik" # Ensure Traefik is used as ingress
spec:
ingressClassName: traefik
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world
port:
number: 3000
host: "your-domain.com" # comment this line for IP only Mode, replace with your domain for Domain Mode
# Optional: Add TLS configuration if you have certificates
# tls:
# - hosts:
# - yourdomain.com
# secretName: your-tls-secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment