k8s-deploy-helper 1.2.0 โ†’ 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
- k8s-deploy-helper ๐Ÿš€
1
+ ### k8s-deploy-helper ๐Ÿš€
2
2
 
3
- k8s-deploy-helper is a simple and beginner-friendly CLI tool that helps you build Docker images and deploy applications to Kubernetes using a guided and automated workflow.
3
+ # k8s-deploy-helper is a simple and beginner-friendly CLI tool that helps you build Docker images and deploy applications to Kubernetes using a guided and automated workflow.
4
4
 
5
- It is designed to reduce the learning curve of Kubernetes while still supporting real-world DevOps practices.
5
+ # It is designed to reduce the learning curve of Kubernetes while still supporting real-world DevOps practices.
6
6
 
7
7
  -----
8
8
 
9
- PROBLEM THIS TOOL SOLVES ๐Ÿงฉ
9
+ ### PROBLEM THIS TOOL SOLVES ๐Ÿงฉ
10
10
 
11
- Deploying an application to Kubernetes usually involves many manual steps:
11
+ ## Deploying an application to Kubernetes usually involves many manual steps:
12
12
 
13
13
  โ€ข Creating and maintaining a Dockerfile
14
14
  โ€ข Writing Kubernetes YAML files (Deployment, Service, etc.)
@@ -16,15 +16,15 @@ Deploying an application to Kubernetes usually involves many manual steps:
16
16
  โ€ข Managing Docker registry authentication
17
17
  โ€ข Debugging unclear or low-level runtime errors
18
18
 
19
- For beginners and even intermediate developers, this process can be confusing, time-consuming, and error-prone.
19
+ # For beginners and even intermediate developers, this process can be confusing, time-consuming, and error-prone.
20
20
 
21
- k8s-deploy-helper removes this complexity by automating these steps and guiding the user through a clear, predictable workflow.
21
+ # k8s-deploy-helper removes this complexity by automating these steps and guiding the user through a clear, predictable workflow.
22
22
 
23
23
  -----
24
24
 
25
- WHAT THIS TOOL DOES โš™๏ธ
25
+ ### WHAT THIS TOOL DOES โš™๏ธ
26
26
 
27
- k8s-deploy-helper automates the full deployment process by:
27
+ ## k8s-deploy-helper automates the full deployment process by:
28
28
 
29
29
  โ€ข Automatically generating missing Docker and Kubernetes configuration files
30
30
  โ€ข Building Docker images for your application
@@ -38,85 +38,81 @@ The tool handles the deployment.
38
38
 
39
39
  -----
40
40
 
41
- REQUIREMENTS (BEGINNER FRIENDLY) ๐Ÿ› ๏ธ
42
-
43
- Minimum setup for local usage:
41
+ ### REQUIREMENTS (BEGINNER FRIENDLY) ๐Ÿ› ๏ธ
44
42
 
43
+ # Minimum setup for local usage:
45
44
  โ€ข Docker Desktop installed
46
45
  โ€ข Kubernetes enabled inside Docker Desktop
47
46
 
48
- Docker Desktop already includes:
47
+ # Docker Desktop already includes:
49
48
  โ€ข Docker
50
49
  โ€ข kubectl
51
50
  โ€ข A local Kubernetes cluster
52
51
 
53
- To verify Kubernetes is running:
54
-
55
- kubectl get nodes
52
+ # To verify Kubernetes is running:
53
+ kubectl get nodes
56
54
 
57
55
  -----
58
56
 
59
- INSTALLATION ๐Ÿ“ฆ
57
+ ### INSTALLATION ๐Ÿ“ฆ
60
58
 
61
- Install the package globally using npm:
59
+ # Install the package globally using npm:
62
60
  npm install -g k8s-deploy-helper
63
61
 
64
- Verify the installation:
62
+ # Verify the installation:
65
63
  k8s-deploy --version
66
64
 
67
65
  -----
68
66
 
69
- HOW TO USE (STEP-BY-STEP) โ–ถ๏ธ
67
+ ### HOW TO USE (STEP-BY-STEP) โ–ถ๏ธ
70
68
 
71
- STEP 1: INITIALIZE THE PROJECT โญ
69
+ ## STEP 1: INITIALIZE THE PROJECT โญ
72
70
 
73
- If your project does not already have a Dockerfile or k8s.config.json,
74
- run:
71
+ # If your project does not already have a Dockerfile or k8s.config.json, run:
75
72
  k8s-deploy init
76
73
 
77
- This command will:
74
+ # This command will:
78
75
  โ€ข Create a basic Dockerfile
79
76
  โ€ข Create a k8s.config.json configuration file
80
77
  โ€ข Prepare your project for Kubernetes deployment
81
78
 
82
- You can modify these files later to match your application needs.
79
+ # You can modify these files later to match your application needs.
83
80
 
84
- STEP 2: DEPLOY LOCALLY (RECOMMENDED FOR BEGINNERS) ๐Ÿงช
81
+ ## STEP 2: DEPLOY LOCALLY (RECOMMENDED FOR BEGINNERS) ๐Ÿงช
85
82
 
86
- For first-time users, deploy without using Docker Hub or any container registry:
83
+ ## For first-time users, deploy without using Docker Hub or any container registry:
87
84
  k8s-deploy deploy --local
88
85
 
89
- What happens during local deployment:
86
+ ## What happens during local deployment:
90
87
  โ€ข The Docker image is built locally
91
88
  โ€ข Image push to a registry is skipped
92
89
  โ€ข Kubernetes uses the local image
93
90
  โ€ข The application is deployed to the local Kubernetes cluster
94
91
 
95
- No Docker Hub account or login is required.
92
+ # No Docker Hub account or login is required.
96
93
 
97
- STEP 3: STANDARD DEPLOYMENT (OPTIONAL) ๐ŸŒ
94
+ ## STEP 3: STANDARD DEPLOYMENT (OPTIONAL) ๐ŸŒ
98
95
 
99
- Once you are comfortable and logged into a container registry,
100
- run:
96
+ # Once you are comfortable and logged into a container registry, run:
101
97
  k8s-deploy deploy
102
98
 
103
- This will:
99
+ ### This will:
104
100
  โ€ข Build the Docker image
105
101
  โ€ข Push the image to the configured registry
106
102
  โ€ข Deploy the application to Kubernetes
107
103
 
108
104
  -----
109
105
 
110
- FILES CREATED BY THE TOOL ๐Ÿ“
106
+ ### FILES CREATED BY THE TOOL ๐Ÿ“
111
107
 
112
- After running the commands, the following files will exist in your project:
108
+ # After running the commands, the following files will exist in your project:
113
109
 
114
110
  Dockerfile
115
111
  k8s.config.json
116
112
  deployment.yaml
117
113
  service.yaml
118
114
 
119
- These files can be:
115
+ # These files can be:
120
116
  โ€ข Reviewed
121
117
  โ€ข Modified
122
118
  โ€ข Committed to Git
@@ -124,9 +120,9 @@ These files can be:
124
120
 
125
121
  -----
126
122
 
127
- WHAT HAPPENS INTERNALLY ๐Ÿ”
123
+ ### WHAT HAPPENS INTERNALLY ๐Ÿ”
128
124
 
129
- When you run the deploy command, the tool performs the following steps:
125
+ # When you run the deploy command, the tool performs the following steps:
130
126
 
131
127
  โ€ข Checks for required files
132
128
  โ€ข Verifies Docker and Kubernetes availability
@@ -134,19 +130,19 @@ When you run the deploy command, the tool performs the following steps:
134
130
  โ€ข Generates Kubernetes YAML files
135
131
  โ€ข Applies resources using kubectl
136
132
 
137
- Each step is logged clearly so you can understand what is happening.
133
+ # Each step is logged clearly so you can understand what is happening.
138
134
 
139
135
  -----
140
136
 
141
- WHY THIS TOOL IS VALUABLE โญ
137
+ ### WHY THIS TOOL IS VALUABLE โญ
142
138
 
143
- Without this tool:
139
+ ## Without this tool:
144
140
  โ€ข You manually write Kubernetes YAML
145
141
  โ€ข You manage Docker commands yourself
146
142
  โ€ข You deal with registry authentication issues
147
143
  โ€ข Kubernetes feels complex and fragile
148
144
 
149
- With this tool:
145
+ ## With this tool:
150
146
  โ€ข One-command deployment
151
147
  โ€ข Beginner-safe defaults
152
148
  โ€ข Hands-on Kubernetes experience
@@ -154,7 +150,5 @@ With this tool:
154
150
 
155
151
  -----
156
152
 
157
- AUTHOR ๐Ÿ‘จโ€๐Ÿ’ป
158
-
153
+ ### AUTHOR ๐Ÿ‘จโ€๐Ÿ’ป
159
154
  Lokesh Shimpi
160
- Built to simplify Kubernetes deployment and demonstrate real-world DevOps engineering.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "k8s-deploy-helper",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "CLI tool to build, push and deploy applications to Kubernetes",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,33 +1,72 @@
1
1
  import fs from 'fs';
2
2
 
3
- export function generateDockerfile() {
4
- if (fs.existsSync('Dockerfile')) return;
3
+ export function generateDockerfiles() {
4
+ const hasServer = fs.existsSync('server');
5
+ const hasClient = fs.existsSync('client');
5
6
 
6
- const dockerfile = `
7
+ // Backend Dockerfile
8
+ if (hasServer && !fs.existsSync('Dockerfile.backend')) {
9
+ const backendDockerfile = `
7
10
  FROM node:18-alpine
11
+
8
12
  WORKDIR /app
13
+
9
14
  COPY server/package*.json ./
10
15
  RUN npm install
16
+
11
17
  COPY server .
18
+
12
19
  EXPOSE 5000
13
20
  CMD ["npm", "start"]
14
21
  `.trim();
15
22
 
16
- fs.writeFileSync('Dockerfile', dockerfile);
17
- console.log('โœ… Dockerfile created');
23
+ fs.writeFileSync('Dockerfile.backend', backendDockerfile);
24
+ console.log('โœ… Backend Dockerfile created (Dockerfile.backend)');
25
+ } else if (hasServer) {
26
+ console.log('โ„น๏ธ Backend Dockerfile already exists. Skipping.');
27
+ }
28
+
29
+ // Frontend Dockerfile
30
+ if (hasClient && !fs.existsSync('Dockerfile.frontend')) {
31
+ const frontendDockerfile = `
32
+ FROM node:18-alpine AS build
33
+
34
+ WORKDIR /app
35
+
36
+ COPY client/package*.json ./
37
+ RUN npm install
38
+
39
+ COPY client .
40
+ RUN npm run build
41
+
42
+ FROM nginx:alpine
43
+ COPY --from=build /app/build /usr/share/nginx/html
44
+
45
+ EXPOSE 80
46
+ CMD ["nginx", "-g", "daemon off;"]
47
+ `.trim();
48
+
49
+ fs.writeFileSync('Dockerfile.frontend', frontendDockerfile);
50
+ console.log('โœ… Frontend Dockerfile created (Dockerfile.frontend)');
51
+ } else if (hasClient) {
52
+ console.log('โ„น๏ธ Frontend Dockerfile already exists. Skipping.');
53
+ }
18
54
  }
19
55
 
20
56
  export function generateK8sConfig() {
21
- if (fs.existsSync('k8s.config.json')) return;
57
+ if (fs.existsSync('k8s.config.json')) {
58
+ console.log('โ„น๏ธ k8s.config.json already exists. Skipping.');
59
+ return;
60
+ }
22
61
 
23
62
  const config = {
24
63
  appName: 'my-app',
25
64
  namespace: 'default',
26
65
  docker: {
27
- image: 'your-docker-username/my-app',
66
+ image: 'your-docker-username/my-app-backend',
28
67
  tag: 'latest',
29
68
  context: '.',
30
- dockerfile: 'Dockerfile'
69
+ dockerfile: 'Dockerfile.backend'
31
70
  },
32
71
  kubernetes: {
33
72
  replicas: 1,
@@ -1,11 +1,21 @@
1
- import { generateDockerfile, generateK8sConfig } from './generateFiles.js';
1
+ import fs from 'fs';
2
+ import { generateDockerfiles, generateK8sConfig } from './generateFiles.js';
2
3
 
3
4
  export function initProject() {
4
- console.log('๐Ÿ”ง Initializing project for Kubernetes deployment...\n');
5
+ console.log('\n๐Ÿ”ง Initializing project for Kubernetes deployment...\n');
5
6
 
6
- generateDockerfile();
7
+ const hasClient = fs.existsSync('client');
8
+ const hasServer = fs.existsSync('server');
9
+
10
+ if (!hasClient && !hasServer) {
11
+ console.error('โŒ No client/ or server/ directory found.');
12
+ console.error('๐Ÿ‘‰ Run this command from the project root.');
13
+ process.exit(1);
14
+ }
15
+
16
+ generateDockerfiles();
7
17
  generateK8sConfig();
8
18
 
9
- console.log('\n๐ŸŽ‰ Initialization complete');
10
- console.log('๐Ÿ‘‰ Update k8s.config.json with your Docker username');
19
+ console.log('\nโœ… Initialization completed successfully.');
20
+ console.log('๐Ÿ‘‰ Review generated files before running deployment.\n');
11
21
  }
@@ -0,0 +1,33 @@
1
+ import { execa } from 'execa';
2
+
3
+ export async function checkEnvironment() {
4
+ // 1. Check Docker availability
5
+ try {
6
+ await execa('docker', ['info'], { stdio: 'ignore' });
7
+ } catch {
8
+ throw new Error(
9
+ 'Docker is not running.\n' +
10
+ '๐Ÿ‘‰ Please start Docker Desktop and try again.'
11
+ );
12
+ }
13
+
14
+ // 2. Check kubectl availability
15
+ try {
16
+ await execa('kubectl', ['version', '--client'], { stdio: 'ignore' });
17
+ } catch {
18
+ throw new Error(
19
+ 'kubectl is not available.\n' +
20
+ '๐Ÿ‘‰ Enable Kubernetes in Docker Desktop or install kubectl.'
21
+ );
22
+ }
23
+
24
+ // 3. Check Kubernetes cluster connectivity
25
+ try {
26
+ await execa('kubectl', ['cluster-info'], { stdio: 'ignore' });
27
+ } catch {
28
+ throw new Error(
29
+ 'Kubernetes cluster is not reachable.\n' +
30
+ '๐Ÿ‘‰ Enable Kubernetes in Docker Desktop and wait until it is ready.'
31
+ );
32
+ }
33
+ }