Open Alvise88 opened 2 years ago
It seems like recent version already support cdk8s and cdk8s+.
docker run -i --entrypoint sh docker.io/denoland/deno:1.30.3 <<\EOF
deno run -A - <<\EOOF
import * as kplus from 'npm:cdk8s-plus-25'
import * as cdk8s from 'npm:cdk8s'
const app = new cdk8s.App()
const chart = new cdk8s.Chart(app, 'ch101')
const deploy203 = new kplus.Deployment(chart, 'd203', {
replicas: 2,
containers: [
{
image: 'nginx',
securityContext: { ensureNonRoot: false, readOnlyRootFilesystem: false}
}
],
})
new kplus.Service(chart, 'srv987', {
selector: deploy203,
ports: [ { port: 80, targetPort: 8080}]
});
console.log(app.synthYaml())
EOOF
EOF
output
apiVersion: apps/v1
kind: Deployment
metadata:
name: ch101-d203-c886a9fd
spec:
minReadySeconds: 0
progressDeadlineSeconds: 600
replicas: 2
selector:
matchLabels:
cdk8s.io/metadata.addr: ch101-d203-c8cfa8e5
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
cdk8s.io/metadata.addr: ch101-d203-c8cfa8e5
spec:
automountServiceAccountToken: false
containers:
- image: nginx
imagePullPolicy: Always
name: main
resources:
limits:
cpu: 1500m
memory: 2048Mi
requests:
cpu: 1000m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: false
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext:
fsGroupChangePolicy: Always
runAsNonRoot: true
setHostnameAsFQDN: false
---
apiVersion: v1
kind: Service
metadata:
name: ch101-srv987-c8aad50a
spec:
externalIPs: []
ports:
- port: 80
targetPort: 8080
selector:
cdk8s.io/metadata.addr: ch101-d203-c8cfa8e5
type: ClusterIP
I've been using cdk8s with Deno for a while now since they introduced npm support. Code itself runs fine, but there are some gaps. For example CLI installation npm install -g cdk8s-cli
and cdk8s init typescript-app
both assumes you're using NodeJS. But I don't see any technical difficulties supporting Deno at this point.
Edit:
Posting from slack for visibility.
cdk8s
package itself was working fine for me. From https://github.com/cdk8s-team/cdk8s/issues/1978
# cdk8s.yaml:
language: typescript
app: deno run --allow-env --allow-write --allow-read main.ts
imports:
- k8s
I believe deno equivalent of npx cdk8s synth
is deno run --allow-env --allow-read npm:cdk8s-cli synth
But I get this error.
Error: ENOENT: no such file or directory, readdir
at __node_internal_captureLargerStackTrace (ext:deno_node/internal/errors.ts:91:11)
at __node_internal_uvException (ext:deno_node/internal/errors.ts:184:12)
at denoErrorToNodeError (ext:deno_node/internal/errors.ts:1845:16)
at Object.readdirSync (ext:deno_node/_fs/_fs_readdir.ts:73:15)
....
So I still needed to use node/npm for cdk8s-cli
I've no idea whether I'm doing something wrong, but even though a simple cdk8s examples work without a problem with Deno, I've stumbled upon the following with Helm
:
error: Uncaught ReferenceError: require is not defined
const { http, https } = require('follow-redirects');
with error location being node_modules/.deno/cdk8s@2.7.56/node_modules/cdk8s/lib/_loadurl.js:8:25
.
Even with the latest version of deno it doesn't seem possible to use cdk8s.
Deno: v1.21.3