I'm new in node.js, so any comments and suggestion will be appreciated. Can anyone suggest me, how can I add readiness probe for the deployment using javascript client via k8s API.
Here below .js the script, that we are using to create deployment. I added readiness section under 'const container' section, but I'm not sure that this changes are correct.
const k8sApi = kc.makeApiClient(k8s.AppsV1Api);
const createDeploymentObject = ({
sourceDeployment,
namespace,
account,
deploymentName,
}) => k8sApi.readNamespacedDeployment(sourceDeployment, namespace)
.then((response) => {
const {
apiVersion,
kind,
metadata: {
labels,
name,
},
spec,
} = response.body;
const deployment = {
apiVersion,
kind,
metadata: {
labels,
name,
namespace,
},
spec,
};
deployment.metadata.name = deploymentName
|| helpers.createK8sName(deployment.metadata.name, account);
deployment.metadata.labels.aid = account;
deployment.spec.replicas = 1;
deployment.spec.selector.matchLabels.aid = account;
deployment.spec.template.metadata.labels.aid = account;
const envServiceId = deployment.spec.template.spec.containers
.find((c) => c.name === 'cp-ksql-server')
.env
.find((e) => e.name === 'KSQL_KSQL_SERVICE_ID');
envServiceId.value = helpers.createKsqlServiceId(account);
const container = deployment.spec.template.spec.containers.find((c) => c.name === 'cp-ksql-server');
container.readinessProbe = {
exec: {
command: ['/bin/bash', '-c', 'curl -s -m 2 http://localhost:8088/healthcheck | grep true']},
initialDelaySeconds: 30,
periodSeconds: 10,
successThreshold: 1,
timeoutSeconds: 1,
failureThreshold: 3
};
console.log(JSON.stringify(container, null, 2));
return deployment;
});