Skip to content

Instantly share code, notes, and snippets.

@metral
Forked from lblackstone/after.ts
Created February 27, 2020 03:29
Show Gist options
  • Save metral/d7ff37e348609ee88654a2a1abfd7b9a to your computer and use it in GitHub Desktop.
Save metral/d7ff37e348609ee88654a2a1abfd7b9a to your computer and use it in GitHub Desktop.
// 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});
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