Kubernetes manifests cheatsheet
Kubernetes manifests: Services and Ingress
4 common Kubernetes manifests tasks.
Service (internal)
Give pods a stable internal address and spread traffic across them.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
Service (public load balancer)
Ask the cloud provider for an external load balancer.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
type: LoadBalancer
selector:
app: web
ports:
- port: 80
targetPort: 80
Ingress with TLS
Route a host name to a Service and terminate TLS with a certificate Secret.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: web
spec:
ingressClassName: nginx
tls:
- hosts: [www.example.com]
secretName: web-tls
rules:
- host: www.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80
Deny all ingress traffic by default
Block all incoming traffic to pods in a namespace, then allow what you need.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-ingress
spec:
podSelector: {}
policyTypes:
- Ingress