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 +39 -45
- package/package.json +1 -1
- package/src/init/generateFiles.js +47 -8
- package/src/init/initProject.js +15 -5
- package/src/preflight/checkEnvironment.js +33 -0
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,33 +1,72 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
|
|
3
|
-
export function
|
|
4
|
-
|
|
3
|
+
export function generateDockerfiles() {
|
|
4
|
+
const hasServer = fs.existsSync('server');
|
|
5
|
+
const hasClient = fs.existsSync('client');
|
|
5
6
|
|
|
6
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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'))
|
|
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,
|
package/src/init/initProject.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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
|
|
10
|
-
console.log('๐
|
|
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
|
+
}
|