Repository: cdk8s-team/cdk8s-plus
Pull request #1138 (2022-09-13 21:38:56)

feat(deployment): set default replica count to 2
Replicas in Kubernetes enable the customer to mention how many pods needs to be spin up to support the service functionality. Currently we have this set to 1. Updating it to `2` to align with best practices.

Signed-off-by: Vinayak Kukreja <vinakuk@amazon.com>

Resolves https://github.com/cdk8s-team/cdk8s-plus/issues/812


Patch:
diff --git a/src/deployment.ts b/src/deployment.ts
index 5c642fdc..75b3838e 100644
--- a/src/deployment.ts
+++ b/src/deployment.ts
@@ -14,7 +14,7 @@ export interface DeploymentProps extends workload.WorkloadProps {
   /**
    * Number of desired pods.
    *
-   * @default 1
+   * @default 2
    */
   readonly replicas?: number;
 
@@ -156,7 +156,7 @@ export class Deployment extends workload.Workload {
       throw new Error(`'progressDeadline' (${this.progressDeadline.toSeconds()}s) must be greater than 'minReady' (${this.minReady.toSeconds()}s)`);
     }
 
-    this.replicas = props.replicas ?? 1;
+    this.replicas = props.replicas ?? 2;
     this.strategy = props.strategy ?? DeploymentStrategy.rollingUpdate();
   }
 


Test patch:
diff --git a/test/__snapshots__/deployment.test.ts.snap b/test/__snapshots__/deployment.test.ts.snap
index 019007b5..03cfcab6 100644
--- a/test/__snapshots__/deployment.test.ts.snap
+++ b/test/__snapshots__/deployment.test.ts.snap
@@ -11,7 +11,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -142,7 +142,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -246,7 +246,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -349,7 +349,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Redis-c8b1633b",
@@ -421,7 +421,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Redis-c8b1633b",
@@ -512,7 +512,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Redis-c8b1633b",
@@ -602,7 +602,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Redis-c8b1633b",
@@ -668,7 +668,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -756,7 +756,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Redis-c8b1633b",
@@ -822,7 +822,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -907,7 +907,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -1000,7 +1000,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -1090,7 +1090,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Redis-c8b1633b",
@@ -1156,7 +1156,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -1244,7 +1244,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Redis-c8b1633b",
@@ -1310,7 +1310,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -1395,7 +1395,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -1488,7 +1488,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
@@ -1578,7 +1578,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -1666,7 +1666,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
diff --git a/test/__snapshots__/network-policy.test.ts.snap b/test/__snapshots__/network-policy.test.ts.snap
index cd4552ff..9691aaa4 100644
--- a/test/__snapshots__/network-policy.test.ts.snap
+++ b/test/__snapshots__/network-policy.test.ts.snap
@@ -279,7 +279,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -1278,7 +1278,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -2165,7 +2165,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Web-c8b65d84",
diff --git a/test/__snapshots__/pod.test.ts.snap b/test/__snapshots__/pod.test.ts.snap
index 72e2aee6..22b294b7 100644
--- a/test/__snapshots__/pod.test.ts.snap
+++ b/test/__snapshots__/pod.test.ts.snap
@@ -1450,7 +1450,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -2915,7 +2915,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
@@ -4373,7 +4373,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
diff --git a/test/__snapshots__/service.test.ts.snap b/test/__snapshots__/service.test.ts.snap
index faaaa8c3..e7a52b8b 100644
--- a/test/__snapshots__/service.test.ts.snap
+++ b/test/__snapshots__/service.test.ts.snap
@@ -43,7 +43,7 @@ Array [
     "spec": Object {
       "minReadySeconds": 0,
       "progressDeadlineSeconds": 600,
-      "replicas": 1,
+      "replicas": 2,
       "selector": Object {
         "matchLabels": Object {
           "cdk8s.io/metadata.addr": "test-Deployment-c83f5e59",
diff --git a/test/deployment.test.ts b/test/deployment.test.ts
index c0cb32dd..6bb91155 100644
--- a/test/deployment.test.ts
+++ b/test/deployment.test.ts
@@ -115,6 +115,8 @@ test('Expose uses the correct default values', () => {
   expect(spec.ports![0].targetPort).toEqual(9300);
   expect(spec.ports![0].port).toEqual(9300);
 
+  const replicas = Testing.synth(chart)[0].spec.replicas;
+  expect(replicas).toEqual(2);
 });
 
 test('Expose can set service and port details', () => {