Writing Skills
writing-skills
效率与协作技能,来自 obra/superpowers,查看原文获取完整用途和操作说明。
kubernetes-ingress【部署与运维】Implements networking.k8s.io/v1 Ingress resources with HTTP/HTTPS routing, TLS termination, path-based routing, and ingress controller configuration.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Implements networking.k8s.io/v1 Ingress resources for HTTP/HTTPS traffic routing, TLS certificate termination, path-based routing, and ingress controller configuration. When loaded, the model generates production-grade Ingress manifests with proper annotations, TLS configuration, and backend service references.
networking.k8s.io/v1 API version — never extensions/v1beta1ingressClassName explicitly — do not rely on the default class annotationpathType: Prefix or pathType: Exact as appropriateUse this skill when:
Avoid this skill for:
kubernetes-networkpolicy insteadkubernetes-istio insteadSelect Ingress Controller — Choose the ingress controller deployment (nginx, contour, istio envoy, envoy gateway) and identify its supported annotations. Checkpoint: Each controller uses different annotation syntax — verify controller compatibility before writing annotations.
Define Ingress Resource — Create an networking.k8s.io/v1 Ingress with ingressClassName, rules for host/path routing, and TLS configuration. Checkpoint: Every path rule must reference a valid Service name and port number.
Configure TLS Termination — Add TLS rules referencing secret names that contain tls.crt and tls.key. Ensure cert-manager is configured to provision certificates. Checkpoint: The TLS secret must exist in the same namespace as the Ingress, or the rule will be ignored.
Set Path Types — Choose pathType: Exact for precise URL matching, pathType: Prefix for prefix-based routing, or pathType: ImplementationSpecific for controller-dependent behavior. Checkpoint: Never mix Exact and Prefix rules for the same path — the API server will reject conflicting rules.
Apply and Validate — Apply the Ingress manifest and verify the ingress controller creates the corresponding backend configuration. Checkpoint: Run kubectl describe ingress <name> and confirm the Address field is populated and rules are accepted.
Verify End-to-End Routing — Test each path and host rule with curl or a browser to confirm correct backend routing. Checkpoint: Check the ingress controller's access logs to verify requests reach the expected backend service.
A production-grade Ingress routing multiple applications through a single ingress class with TLS termination.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: multi-app-ingress
namespace: production
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "10m"
cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
ingressClassName: nginx
tls:
- hosts:
- app.example.com
- api.example.com
secretName: app-tls-cert
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-frontend
port:
number: 80
- path: /admin
pathType: Prefix
backend:
service:
name: admin-panel
port:
number: 8080
- path: /api/v1
pathType: Prefix
backend:
service:
name: api-gateway
port:
number: 443
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api-gateway
port:
number: 443
Misusing annotations or path types is the most common Ingress error.
# ❌ BAD: Using deprecated extensions/v1beta1 API — removed in Kubernetes 1.22+
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: nginx # ← Deprecated annotation, use ingressClassName
spec:
rules:
- http:
paths:
- path: /api
backend:
serviceName: api-gateway # ← Field removed in v1
servicePort: 443 # ← Field removed in v1
# ❌ BAD: Conflicting path types for the same path
spec:
rules:
- host: app.example.com
http:
paths:
- path: /api
pathType: Exact # ← Exact does not cover /api/anything
backend:
service:
name: api-v1
port:
number: 8080
- path: /api
pathType: Prefix # ← Conflicts with the Exact rule above
backend:
service:
name: api-v2
port:
number: 8080
# ✅ GOOD: Explicit ingressClassName, compatible path types, v1 API
spec:
ingressClassName: nginx
rules:
- host: app.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-v2
port:
number: 8080
TLS configuration with cert-manager integration for automated certificate provisioning.
# ClusterIssuer for Let's Encrypt (create once per cluster)
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: admin@example.com
privateKeySecretRef:
name: letsencrypt-prod-key
solvers:
- http01:
ingress:
class: nginx
# Ingress referencing the cert-manager managed TLS secret
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: secure-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- secure.example.com
secretName: secure-tls-cert
rules:
- host: secure.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: secure-backend
port:
number: 80
networking.k8s.io/v1 API version — never extensions/v1beta1 (removed in Kubernetes 1.22+)ingressClassName explicitly in the spec — do not rely on the deprecated kubernetes.io/ingress.class annotationtls with a valid secret name that contains tls.crt and tls.key certificatesssl-redirect: "true" annotation when TLS is configured to enforce HTTPSpathType: Prefix for general routing and pathType: Exact only for specific URL matchespathType rules — no two rules for the same path with different types (Exact vs Prefix)metadata.annotations block with controller-specific annotations onlyextensions/v1beta1 Ingress API — it has been removed and will fail on modern clustersingressClassName — without it, the ingress controller cannot claim the Ingress resourcepathType: ImplementationSpecific without documenting the controller-specific behaviorpathType: Exact for a path that should also match sub-paths — clients will receive 404 errorsWhen implementing a Kubernetes Ingress, produce the following:
networking.k8s.io/v1 Ingress with ingressClassName, TLS rules, and path-based routing rules.| Skill | Purpose |
|---|---|
kubernetes-networkpolicy | Define network-level firewall rules to complement ingress-layer routing |
kubernetes-services-management | Create the ClusterIP/NodePort Services that serve as Ingress backends |
kubernetes-istio | Implement advanced traffic management (canary, circuit breaking, retries) at the service mesh layer |
cncf/contour | Use Contour as an alternative Ingress controller with Envoy proxy |
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.