-
-
Save metral/35db57c5ebafebb879f4600b7845da83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Define the application configuration and secrets. | |
const configs = new kx.ConfigMap("app-config", { | |
data: { "config": "very important data" } | |
}); | |
const secrets = new kx.Secret("app-secrets", { | |
stringData: { | |
"app-password": new kx.RandomPassword("app-password"), | |
"database-password": config.databasePassword | |
} | |
}); | |
// Define the application Pod. | |
const appConfigPath = "/app/config"; | |
const appPod = new kx.PodBuilder({ | |
containers: [ | |
{ | |
image: "app:1.0.0", | |
env: { | |
"APP_CONFIG_PATH": appConfigPath, | |
"APP_USER": config.user, | |
"APP_PASSWORD": secrets.asEnvValue("app-password"), | |
"APP_DATABASE_PASSWORD": secrets.asEnvValue("database-password"), | |
}, | |
volumeMounts: [ | |
configs.mount(appConfigPath) | |
], | |
} | |
] | |
}); | |
// Create a Kubernetes Deployment using the previous Pod definition. | |
const deployment = new kx.Deployment("nginx", { | |
spec: appPod.asDeploymentSpec( { replicas: 3 } ), | |
}); | |
// Expose the Deployment with a load balancer using a Kubernetes Service. | |
const service = deployment.createService({type: kx.types.ServiceType.LoadBalancer}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
data: | |
config: very important data | |
metadata: | |
name: app-config | |
--- | |
apiVersion: v1 | |
kind: Secret | |
data: | |
app-password: JikkMz9mK2hIRDo3 | |
database-password: Y29uZmlnLmRhdGFiYXNlUGFzc3dvcmQ= | |
metadata: | |
name: app-secrets | |
type: Opaque | |
--- | |
apiVersion: apps/v1 | |
kind: Deployment | |
metadata: | |
name: nginx | |
spec: | |
replicas: 3 | |
selector: | |
matchLabels: | |
app: nginx | |
template: | |
metadata: | |
labels: | |
app: nginx | |
spec: | |
containers: | |
- env: | |
- name: APP_CONFIG_PATH | |
value: /app/config | |
- name: APP_USER | |
value: config.user | |
- name: APP_PASSWORD | |
valueFrom: | |
secretKeyRef: | |
key: app-password | |
name: app-secrets | |
- name: APP_DATABASE_PASSWORD | |
valueFrom: | |
secretKeyRef: | |
key: database-password | |
name: app-secrets | |
image: nginx | |
imagePullPolicy: Always | |
name: nginx | |
ports: | |
- containerPort: 80 | |
name: http | |
volumeMounts: | |
- mountPath: /app/config | |
name: app-config | |
restartPolicy: Always | |
volumes: | |
- configMap: | |
name: app-config | |
name: app-config | |
--- | |
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: nginx | |
spec: | |
ports: | |
- name: http | |
port: 80 | |
targetPort: 80 | |
selector: | |
app: nginx | |
type: LoadBalancer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment