Setting the file. One moment. Service Template · K8S Manifest Generator · wshobson/agents · Skills Docs19
Workflow Orchestration Patterns
57
Nx Workspace Patterns
Trace To Training Data
Web Component Design
83
apiVersion
— line 83
This file
- Number
- 92.6
- Position
- 6 of 6
- Type
- YAML
- Size
- 4 KB
- Lines
- 171
assets/service-template.yaml
YAML·171 lines·4 KB
<instance-name>
13 annotations:
14 description: "Internal service for <app-name>"
15spec:
16 type: ClusterIP
17 selector:
18 app.kubernetes.io/name: <app-name>
19 app.kubernetes.io/instance: <instance-name>
20 ports:
21 - name: http
22 port: 80
23 targetPort: http # Named port from container
24 protocol: TCP
25 sessionAffinity: None
26
27---
28# Template 2: LoadBalancer Service (External Access)
29apiVersion: v1
30kind: Service
31metadata:
32 name: <app-name>-lb
33 namespace: <namespace>
34 labels:
35 app.kubernetes.io/name: <app-name>
36 annotations:
37 # AWS NLB annotations
38 service.beta.kubernetes.io/aws-load-balancer-type: "nlb"
39 service.beta.kubernetes.io/aws-load-balancer-scheme: "internet-facing"
40 service.beta.kubernetes.io/aws-load-balancer-cross-zone-load-balancing-enabled: "true"
41 # SSL certificate (optional)
42 # service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:..."
43spec:
44 type: LoadBalancer
45 externalTrafficPolicy: Local # Preserves client IP
46 selector:
47 app.kubernetes.io/name: <app-name>
48 ports:
49 - name: http
50 port: 80
51 targetPort: http
52 protocol: TCP
53 - name: https
54 port: 443
55 targetPort: https
56 protocol: TCP
57 # Restrict access to specific IPs (optional)
58 # loadBalancerSourceRanges:
59 # - 203.0.113.0/24
60
61---
62# Template 3: NodePort Service (Direct Node Access)
63apiVersion: v1
64kind: Service
65metadata:
66 name: <app-name>-np
67 namespace: <namespace>
68 labels:
69 app.kubernetes.io/name: <app-name>
70spec:
71 type: NodePort
72 selector:
73 app.kubernetes.io/name: <app-name>
74 ports:
75 - name: http
76 port: 80
77 targetPort: 8080
78 nodePort: 30080 # Optional, 30000-32767 range
79 protocol: TCP
80
81---
82# Template 4: Headless Service (StatefulSet)
83apiVersion: v1
84kind: Service
85metadata:
86 name: <app-name>-headless
87 namespace: <namespace>
88 labels:
89 app.kubernetes.io/name: <app-name>
90spec:
91 clusterIP: None # Headless
92 selector:
93 app.kubernetes.io/name: <app-name>
94 ports:
95 - name: client
96 port: 9042
97 targetPort: 9042
98 publishNotReadyAddresses: true # Include not-ready pods in DNS
99
100---
101# Template 5: Multi-Port Service with Metrics
102apiVersion: v1
103kind: Service
104metadata:
105 name: <app-name>-multi
106 namespace: <namespace>
107 labels:
108 app.kubernetes.io/name: <app-name>
109 annotations:
110 prometheus.io/scrape: "true"
111 prometheus.io/port: "9090"
112 prometheus.io/path: "/metrics"
113spec:
114 type: ClusterIP
115 selector:
116 app.kubernetes.io/name: <app-name>
117 ports:
118 - name: http
119 port: 80
120 targetPort: 8080
121 protocol: TCP
122 - name: https
123 port: 443
124 targetPort: 8443
125 protocol: TCP
126 - name: grpc
127 port: 9090
128 targetPort: 9090
129 protocol: TCP
130 - name: metrics
131 port: 9091
132 targetPort: 9091
133 protocol: TCP
134
135---
136# Template 6: Service with Session Affinity
137apiVersion: v1
138kind: Service
139metadata:
140 name: <app-name>-sticky
141 namespace: <namespace>
142 labels:
143 app.kubernetes.io/name: <app-name>
144spec:
145 type: ClusterIP
146 selector:
147 app.kubernetes.io/name: <app-name>
148 ports:
149 - name: http
150 port: 80
151 targetPort: 8080
152 protocol: TCP
153 sessionAffinity: ClientIP
154 sessionAffinityConfig:
155 clientIP:
156 timeoutSeconds: 10800 # 3 hours
157
158---
159# Template 7: ExternalName Service (External Service Mapping)
160apiVersion: v1
161kind: Service
162metadata:
163 name: external-db
164 namespace: <namespace>
165spec:
166 type: ExternalName
167 externalName: db.example.com
168 ports:
169 - port: 5432
170 targetPort: 5432
171 protocol: TCP