@intentius/chant-lexicon-k8s 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+ ---
2
+ skill: chant-k8s-aks
3
+ description: AKS-specific Kubernetes patterns and composites
4
+ user-invocable: true
5
+ ---
6
+
7
+ # AKS Kubernetes Patterns
8
+
9
+ ## AKS Composites Overview
10
+
11
+ These composites produce K8s YAML with AKS-specific annotations and configurations.
12
+
13
+ ### AksWorkloadIdentityServiceAccount — ServiceAccount with Azure client ID annotation
14
+
15
+ ```typescript
16
+ import { AksWorkloadIdentityServiceAccount } from "@intentius/chant-lexicon-k8s";
17
+
18
+ const { serviceAccount, role, roleBinding } = AksWorkloadIdentityServiceAccount({
19
+ name: "app-sa",
20
+ clientId: "12345678-abcd-1234-abcd-123456789012",
21
+ rbacRules: [
22
+ { apiGroups: [""], resources: ["secrets"], verbs: ["get"] },
23
+ ],
24
+ namespace: "prod",
25
+ });
26
+ ```
27
+
28
+ Annotates the ServiceAccount with `azure.workload.identity/client-id` for AKS Workload Identity.
29
+
30
+ ### AgicIngress — Ingress with Application Gateway annotations
31
+
32
+ ```typescript
33
+ import { AgicIngress } from "@intentius/chant-lexicon-k8s";
34
+
35
+ const { ingress } = AgicIngress({
36
+ name: "api-ingress",
37
+ hosts: [
38
+ {
39
+ hostname: "api.example.com",
40
+ paths: [{ path: "/", serviceName: "api", servicePort: 80 }],
41
+ },
42
+ ],
43
+ certificateArn: "keyvault-cert-name",
44
+ healthCheckPath: "/healthz",
45
+ wafPolicyId: "/subscriptions/.../applicationGatewayWebApplicationFirewallPolicies/my-waf",
46
+ cookieAffinity: false,
47
+ });
48
+ ```
49
+
50
+ Features:
51
+ - Auto-sets `appgw.ingress.kubernetes.io/*` annotations
52
+ - SSL redirect enabled by default when `certificateArn` set
53
+ - `wafPolicyId` for WAFv2 integration
54
+ - `healthCheckPath` for backend health probes
55
+ - `cookieAffinity` for session persistence
56
+
57
+ ### AzureDiskStorageClass — StorageClass for Azure Disk CSI
58
+
59
+ ```typescript
60
+ import { AzureDiskStorageClass } from "@intentius/chant-lexicon-k8s";
61
+
62
+ const { storageClass } = AzureDiskStorageClass({
63
+ name: "premium-lrs",
64
+ skuName: "Premium_LRS",
65
+ cachingMode: "ReadOnly",
66
+ allowVolumeExpansion: true,
67
+ });
68
+ ```
69
+
70
+ SKU options: `Premium_LRS`, `StandardSSD_LRS`, `Standard_LRS`, `UltraSSD_LRS`.
71
+
72
+ ### AzureFileStorageClass — StorageClass for Azure Files CSI (ReadWriteMany)
73
+
74
+ ```typescript
75
+ import { AzureFileStorageClass } from "@intentius/chant-lexicon-k8s";
76
+
77
+ const { storageClass } = AzureFileStorageClass({
78
+ name: "azure-files-premium",
79
+ skuName: "Premium_LRS",
80
+ protocol: "smb",
81
+ });
82
+ ```
83
+
84
+ Protocol options: `smb` (default), `nfs`. Use Azure Files when you need ReadWriteMany (shared across pods/nodes). Use Azure Disk for ReadWriteOnce (single pod).
85
+
86
+ ### AksExternalDnsAgent — ExternalDNS for Azure DNS
87
+
88
+ ```typescript
89
+ import { AksExternalDnsAgent } from "@intentius/chant-lexicon-k8s";
90
+
91
+ const result = AksExternalDnsAgent({
92
+ clientId: "12345678-abcd-1234-abcd-123456789012",
93
+ resourceGroup: "my-rg",
94
+ subscriptionId: "sub-id",
95
+ tenantId: "tenant-id",
96
+ domainFilters: ["example.com"],
97
+ txtOwnerId: "my-cluster",
98
+ });
99
+ ```
100
+
101
+ ### AzureMonitorCollector — Azure Monitor + OTel for Log Analytics
102
+
103
+ ```typescript
104
+ import { AzureMonitorCollector } from "@intentius/chant-lexicon-k8s";
105
+
106
+ const result = AzureMonitorCollector({
107
+ workspaceId: "/subscriptions/.../workspaces/my-workspace",
108
+ clusterName: "my-cluster",
109
+ clientId: "12345678-abcd-1234-abcd-123456789012",
110
+ });
111
+ ```
112
+
113
+ ## AKS Workload Identity vs Pod-Managed Identity
114
+
115
+ | Feature | Workload Identity | Pod-Managed Identity (deprecated) |
116
+ |---------|------------------|----------------------------------|
117
+ | K8s annotation needed | Yes (`azure.workload.identity/client-id`) | Yes (`aadpodidbinding` label) |
118
+ | Composite available | **AksWorkloadIdentityServiceAccount** | None (deprecated) |
119
+ | Setup | OIDC issuer + federated credential | AzureIdentity + AzureIdentityBinding CRDs |
120
+ | Security | OIDC token exchange, no NMI pod | NMI DaemonSet intercepts IMDS calls |
121
+ | When to use | Always (recommended) | Legacy only, migrate to Workload Identity |
122
+
123
+ Pod-managed identity (AAD Pod Identity v1) is deprecated. Always use AKS Workload Identity for new workloads.
124
+
125
+ ## AGIC Considerations
126
+
127
+ Application Gateway Ingress Controller (AGIC) manages an Azure Application Gateway:
128
+ - **Application Gateway provisioned in ARM** — the gateway itself is an Azure resource created by the ARM template
129
+ - **AGIC addon** — runs as a pod in the cluster, watches Ingress resources and configures the gateway
130
+ - **Backend pools** — AGIC automatically adds pod IPs to the Application Gateway backend pool
131
+ - **Health probes** — set `healthCheckPath` for proper backend health checking
132
+ - **WAF integration** — attach a WAF policy via `wafPolicyId` for L7 protection
133
+ - **TLS termination** — reference Key Vault certificates via `certificateArn` (the certificate URI or secret name)
134
+
135
+ ## AKS Add-ons
136
+
137
+ Common add-ons managed via AKS (not K8s manifests):
138
+ - **AGIC** — Application Gateway Ingress Controller (required for AgicIngress)
139
+ - **Azure Monitor (Container Insights)** — alternative to AzureMonitorCollector for managed monitoring
140
+ - **AKS Workload Identity** — OIDC-based identity federation (required for AksWorkloadIdentityServiceAccount)
141
+ - **Azure Disk CSI driver** — enabled by default, required for AzureDiskStorageClass
142
+ - **Azure Files CSI driver** — enabled by default, required for AzureFileStorageClass
143
+ - **Azure Key Vault Secrets Provider** — sync Key Vault secrets to K8s Secrets
144
+ - **Azure Policy** — enforce governance policies on cluster resources
145
+
146
+ Configure add-ons via the Azure lexicon (`@intentius/chant-lexicon-azure`) ARM resources.
@@ -0,0 +1,191 @@
1
+ ---
2
+ skill: chant-k8s-gke
3
+ description: GKE-specific Kubernetes patterns and composites
4
+ user-invocable: true
5
+ ---
6
+
7
+ # GKE Kubernetes Patterns
8
+
9
+ ## GKE Composites Overview
10
+
11
+ These composites produce K8s YAML with GKE-specific annotations and configurations.
12
+
13
+ ### WorkloadIdentityServiceAccount — ServiceAccount with GCP SA annotation
14
+
15
+ ```typescript
16
+ import { WorkloadIdentityServiceAccount } from "@intentius/chant-lexicon-k8s";
17
+
18
+ const { serviceAccount, role, roleBinding } = WorkloadIdentityServiceAccount({
19
+ name: "app-sa",
20
+ gcpServiceAccountEmail: "app@my-project.iam.gserviceaccount.com",
21
+ rbacRules: [
22
+ { apiGroups: [""], resources: ["secrets"], verbs: ["get"] },
23
+ ],
24
+ namespace: "prod",
25
+ });
26
+ ```
27
+
28
+ Annotates the ServiceAccount with `iam.gke.io/gcp-service-account` for GKE Workload Identity.
29
+
30
+ ### GceIngress — Ingress with GCE ingress class annotations
31
+
32
+ ```typescript
33
+ import { GceIngress } from "@intentius/chant-lexicon-k8s";
34
+
35
+ const { ingress } = GceIngress({
36
+ name: "api-ingress",
37
+ hosts: [
38
+ {
39
+ hostname: "api.example.com",
40
+ paths: [{ path: "/", serviceName: "api", servicePort: 80 }],
41
+ },
42
+ ],
43
+ staticIpName: "api-ip",
44
+ managedCertificate: "api-cert",
45
+ namespace: "prod",
46
+ });
47
+ ```
48
+
49
+ Features:
50
+ - Sets `kubernetes.io/ingress.class: "gce"` annotation
51
+ - `staticIpName` binds a reserved global static IP via `kubernetes.io/ingress.global-static-ip-name`
52
+ - `managedCertificate` attaches a GKE-managed SSL certificate via `networking.gke.io/managed-certificates`
53
+ - Auto-generates FrontendConfig for SSL redirect when `managedCertificate` is set (override with `sslRedirect: false`)
54
+ - Pairs naturally with Config Connector `ComputeAddress` resources for static IPs
55
+
56
+ ### GkeGateway — Gateway API with GKE gateway classes
57
+
58
+ ```typescript
59
+ import { GkeGateway } from "@intentius/chant-lexicon-k8s";
60
+
61
+ const { gateway, httpRoute } = GkeGateway({
62
+ name: "api-gateway",
63
+ gatewayClassName: "gke-l7-global-external-managed",
64
+ hosts: [
65
+ {
66
+ hostname: "api.example.com",
67
+ paths: [{ path: "/", serviceName: "api", servicePort: 80 }],
68
+ },
69
+ ],
70
+ certificateName: "api-cert",
71
+ namespace: "prod",
72
+ });
73
+ ```
74
+
75
+ Gateway class options:
76
+ - `gke-l7-global-external-managed` — Global external (default)
77
+ - `gke-l7-regional-external-managed` — Regional external
78
+ - `gke-l7-rilb` — Regional internal
79
+
80
+ ### GcePdStorageClass — StorageClass for GCE Persistent Disk CSI
81
+
82
+ ```typescript
83
+ import { GcePdStorageClass } from "@intentius/chant-lexicon-k8s";
84
+
85
+ const { storageClass } = GcePdStorageClass({
86
+ name: "pd-balanced",
87
+ type: "pd-balanced",
88
+ replicationType: "none",
89
+ allowVolumeExpansion: true,
90
+ });
91
+ ```
92
+
93
+ Disk types: `pd-standard`, `pd-ssd`, `pd-balanced` (default), `pd-extreme`.
94
+
95
+ ### FilestoreStorageClass — StorageClass for Filestore CSI (ReadWriteMany)
96
+
97
+ ```typescript
98
+ import { FilestoreStorageClass } from "@intentius/chant-lexicon-k8s";
99
+
100
+ const { storageClass } = FilestoreStorageClass({
101
+ name: "filestore-shared",
102
+ tier: "standard",
103
+ network: "my-vpc",
104
+ });
105
+ ```
106
+
107
+ Use Filestore when you need ReadWriteMany (shared across pods/nodes). Use GCE PD for ReadWriteOnce (single pod).
108
+
109
+ ### GkeExternalDnsAgent — ExternalDNS for Cloud DNS
110
+
111
+ ```typescript
112
+ import { GkeExternalDnsAgent } from "@intentius/chant-lexicon-k8s";
113
+
114
+ const result = GkeExternalDnsAgent({
115
+ gcpServiceAccountEmail: "dns@my-project.iam.gserviceaccount.com",
116
+ gcpProjectId: "my-project",
117
+ domainFilters: ["example.com"],
118
+ txtOwnerId: "my-cluster",
119
+ });
120
+ ```
121
+
122
+ ### GkeFluentBitAgent — DaemonSet for Cloud Logging
123
+
124
+ ```typescript
125
+ import { GkeFluentBitAgent } from "@intentius/chant-lexicon-k8s";
126
+
127
+ const result = GkeFluentBitAgent({
128
+ clusterName: "my-cluster",
129
+ projectId: "my-project",
130
+ gcpServiceAccountEmail: "logging@my-project.iam.gserviceaccount.com",
131
+ });
132
+ ```
133
+
134
+ ### GkeOtelCollector — OTel for Cloud Trace + Cloud Monitoring
135
+
136
+ ```typescript
137
+ import { GkeOtelCollector } from "@intentius/chant-lexicon-k8s";
138
+
139
+ const result = GkeOtelCollector({
140
+ clusterName: "my-cluster",
141
+ projectId: "my-project",
142
+ gcpServiceAccountEmail: "monitoring@my-project.iam.gserviceaccount.com",
143
+ });
144
+ ```
145
+
146
+ ### ConfigConnectorContext — Config Connector namespace bootstrap
147
+
148
+ ```typescript
149
+ import { ConfigConnectorContext } from "@intentius/chant-lexicon-k8s";
150
+
151
+ const { context } = ConfigConnectorContext({
152
+ googleServiceAccountEmail: "cc-sa@my-project.iam.gserviceaccount.com",
153
+ namespace: "config-connector",
154
+ stateIntoSpec: "absent",
155
+ });
156
+ ```
157
+
158
+ Required when using Config Connector to manage GCP resources from within the cluster.
159
+
160
+ ## Workload Identity vs Key-Based Auth
161
+
162
+ | Feature | Workload Identity | Key-based (JSON key file) |
163
+ |---------|------------------|--------------------------|
164
+ | K8s annotation needed | Yes (`iam.gke.io/gcp-service-account`) | No |
165
+ | Composite available | **WorkloadIdentityServiceAccount** | None needed (mount key as Secret) |
166
+ | Setup | GKE cluster WI enabled + IAM binding | Create key → K8s Secret → volume mount |
167
+ | Security | No long-lived credentials, auto-rotated | Static key, must rotate manually |
168
+ | When to use | Always (recommended) | Legacy workloads, non-GKE clusters |
169
+
170
+ Workload Identity is the recommended approach for all GKE workloads. Key-based auth requires no K8s-side composite — create a Secret from the JSON key and mount it.
171
+
172
+ ## Config Connector Considerations
173
+
174
+ Config Connector (CC) runs as a GKE add-on and manages GCP resources declaratively via K8s CRDs:
175
+ - **Bootstrap cluster required** — CC needs an existing GKE cluster to run in; use `npm run bootstrap` to create one
176
+ - **CC service account** — a GCP SA with editor/IAM roles, bound to the CC controller pod via Workload Identity
177
+ - **Reconciliation** — CC continuously reconciles; deleting a CC resource deletes the underlying GCP resource
178
+ - **ConfigConnectorContext** — use the composite to configure CC per-namespace (SA email, stateIntoSpec policy)
179
+
180
+ ## GKE Add-ons
181
+
182
+ Common add-ons managed via GKE (not K8s manifests):
183
+ - **Config Connector** — manage GCP resources as K8s CRDs
184
+ - **Workload Identity** — pod-to-GCP-SA identity federation (required for WorkloadIdentityServiceAccount)
185
+ - **GKE Gateway Controller** — Gateway API implementation (required for GkeGateway)
186
+ - **GKE managed Prometheus** — alternative to GkeOtelCollector for metrics
187
+ - **GKE Dataplane V2** — eBPF-based networking with built-in NetworkPolicy enforcement
188
+ - **Filestore CSI driver** — required for FilestoreStorageClass
189
+ - **Compute Engine persistent disk CSI driver** — enabled by default, required for GcePdStorageClass
190
+
191
+ Configure add-ons via the GCP lexicon (`@intentius/chant-lexicon-gcp`) Config Connector resources.
@@ -0,0 +1,183 @@
1
+ ---
2
+ skill: kubernetes-patterns
3
+ description: Kubernetes deployment strategies, stateful workloads, RBAC, and networking patterns
4
+ user-invocable: true
5
+ ---
6
+
7
+ # Kubernetes Infrastructure Patterns
8
+
9
+ ## Deployment Strategies
10
+
11
+ ### Rolling Update (default)
12
+
13
+ Gradually replaces pods with zero downtime. Configure surge and unavailability:
14
+
15
+ ```typescript
16
+ import { WebApp } from "@intentius/chant-lexicon-k8s";
17
+
18
+ const { deployment, service } = WebApp({
19
+ name: "api",
20
+ image: "api:2.0",
21
+ replicas: 4,
22
+ strategy: {
23
+ type: "RollingUpdate",
24
+ rollingUpdate: { maxSurge: "25%", maxUnavailable: "25%" },
25
+ },
26
+ });
27
+ ```
28
+
29
+ ### Blue/Green Deployment
30
+
31
+ Run two full deployments and switch traffic by updating the Service selector:
32
+
33
+ ```typescript
34
+ import { WebApp } from "@intentius/chant-lexicon-k8s";
35
+
36
+ const blue = WebApp({ name: "app-blue", image: "app:1.0", replicas: 3 });
37
+ const green = WebApp({ name: "app-green", image: "app:2.0", replicas: 3 });
38
+
39
+ // Switch traffic: update the Service selector to point at green
40
+ // kubectl patch svc app -p '{"spec":{"selector":{"version":"green"}}}'
41
+ ```
42
+
43
+ ### Canary Deployment
44
+
45
+ Deploy a small replica set alongside the main deployment to test new versions:
46
+
47
+ ```typescript
48
+ import { AutoscaledService, WebApp } from "@intentius/chant-lexicon-k8s";
49
+
50
+ const main = AutoscaledService({
51
+ name: "app",
52
+ image: "app:1.0",
53
+ port: 8080,
54
+ minReplicas: 9,
55
+ maxReplicas: 20,
56
+ });
57
+
58
+ const canary = WebApp({
59
+ name: "app-canary",
60
+ image: "app:2.0",
61
+ replicas: 1,
62
+ labels: { track: "canary" },
63
+ });
64
+ ```
65
+
66
+ Both share the same `app.kubernetes.io/name` label so the Service routes traffic to both.
67
+
68
+ ## Stateful Workloads
69
+
70
+ ### StatefulSet with Persistent Storage
71
+
72
+ Use `StatefulApp` for databases, caches, and other stateful services:
73
+
74
+ ```typescript
75
+ import { StatefulApp } from "@intentius/chant-lexicon-k8s";
76
+
77
+ const { statefulSet, service } = StatefulApp({
78
+ name: "postgres",
79
+ image: "postgres:16",
80
+ port: 5432,
81
+ replicas: 3,
82
+ storageSize: "50Gi",
83
+ storageClass: "gp3-encrypted",
84
+ env: [
85
+ { name: "POSTGRES_DB", value: "app" },
86
+ { name: "POSTGRES_PASSWORD", valueFrom: { secretKeyRef: { name: "pg-creds", key: "password" } } },
87
+ ],
88
+ });
89
+ ```
90
+
91
+ ### Headless Service for StatefulSet Discovery
92
+
93
+ `StatefulApp` creates a headless Service (`clusterIP: None`) automatically. Pods are addressable as `postgres-0.postgres.namespace.svc.cluster.local`.
94
+
95
+ ### PersistentVolumeClaim Retention
96
+
97
+ StatefulSet PVCs persist after pod deletion by default. To clean up:
98
+
99
+ ```bash
100
+ kubectl delete pvc -l app.kubernetes.io/name=postgres
101
+ ```
102
+
103
+ ## RBAC Patterns
104
+
105
+ ### Least-Privilege ServiceAccount
106
+
107
+ Use `WorkerPool` or `BatchJob` composites which create scoped RBAC automatically:
108
+
109
+ ```typescript
110
+ import { WorkerPool } from "@intentius/chant-lexicon-k8s";
111
+
112
+ const { deployment, serviceAccount, role, roleBinding } = WorkerPool({
113
+ name: "queue-worker",
114
+ image: "worker:1.0",
115
+ replicas: 3,
116
+ rbacRules: [
117
+ { apiGroups: [""], resources: ["configmaps"], verbs: ["get", "list"] },
118
+ { apiGroups: ["batch"], resources: ["jobs"], verbs: ["create"] },
119
+ ],
120
+ });
121
+ ```
122
+
123
+ ### Namespace-Scoped vs Cluster-Scoped
124
+
125
+ - Use `Role` + `RoleBinding` for namespace-scoped permissions (default in composites)
126
+ - Use `ClusterRole` + `ClusterRoleBinding` for cross-namespace access (node agents, monitoring)
127
+
128
+ ```typescript
129
+ import { NodeAgent } from "@intentius/chant-lexicon-k8s";
130
+
131
+ const { daemonSet, serviceAccount, clusterRole, clusterRoleBinding } = NodeAgent({
132
+ name: "log-agent",
133
+ image: "fluent-bit:2.2",
134
+ rbacRules: [
135
+ { apiGroups: [""], resources: ["pods", "namespaces"], verbs: ["get", "list", "watch"] },
136
+ ],
137
+ });
138
+ ```
139
+
140
+ ## Networking Patterns
141
+
142
+ ### Default-Deny with Selective Allow
143
+
144
+ Use `NamespaceEnv` for namespace-level isolation, then `NetworkIsolatedApp` for per-app rules:
145
+
146
+ ```typescript
147
+ import { NamespaceEnv, NetworkIsolatedApp } from "@intentius/chant-lexicon-k8s";
148
+
149
+ const ns = NamespaceEnv({
150
+ name: "prod",
151
+ defaultDenyIngress: true,
152
+ defaultDenyEgress: true,
153
+ cpuLimit: "8",
154
+ memoryLimit: "16Gi",
155
+ });
156
+
157
+ const app = NetworkIsolatedApp({
158
+ name: "api",
159
+ image: "api:1.0",
160
+ port: 8080,
161
+ namespace: "prod",
162
+ allowIngressFrom: [
163
+ { podSelector: { "app.kubernetes.io/name": "gateway" } },
164
+ ],
165
+ allowEgressTo: [
166
+ { podSelector: { "app.kubernetes.io/name": "postgres" }, ports: [{ port: 5432 }] },
167
+ ],
168
+ });
169
+ ```
170
+
171
+ ### Service Mesh (Istio/Linkerd)
172
+
173
+ For mTLS between services, use a sidecar-injected namespace:
174
+
175
+ ```bash
176
+ kubectl label namespace prod istio-injection=enabled
177
+ ```
178
+
179
+ Then deploy with standard composites. The mesh proxy is injected automatically.
180
+
181
+ ### DNS-Based Service Discovery
182
+
183
+ Services are discoverable at `<service>.<namespace>.svc.cluster.local`. For headless services (StatefulSets), individual pods are at `<pod>.<service>.<namespace>.svc.cluster.local`.