KubeView is a Kubernetes preview environment tool that allows you to create, manage, and monitor preview environments directly from your GitHub repository. It provides both a GitHub Actions integration and a command-line interface (CLI) tool for seamless integration into your development workflow.
- Node.js and npm installed on your machine
- Access to a Kubernetes cluster
kubernetespreviewenvdemo.mp4
-
Clone Repository:
git clone https://github.com/Nikunj0601/KubeView.git
-
Navigate to Project Directory:
cd KubeView cd kube-view
-
Install Dependencies:
npm install
-
Set Environment Variables: Create a
.envfile based on the provided example.env.examplefile and update the variables as required. -
Provide Kubernetes Cluster Configuration: Ensure you have access to a Kubernetes cluster and provide the cluster configuration in
./kube-view/configfile. -
Start KubeView Server:
npm run start
-
Install CLI Tool:
cd ../kubeview-cli npm install -g .
To use KubeView, you have two options: GitHub Actions integration or CLI tool.
- Export GitHub Token: Before using the KubeView CLI, export your GitHub token by executing:
export GITHUB_TOKEN='your_token' - Generate API Key: First, generate an API key using the
kubeview api-key createcommand. - Export API Key: Before using the other KubeView CLI commands, export your API Key that you created earlier by executing:
export KUBEVIEW_API_KEY='you_api_key'
- Export GitHub Token: Before using the KubeView CLI, export your GitHub token by executing:
export GITHUB_TOKEN='your_token' - Generate API Key: First, generate an API key using the
kubeview api-key createcommand. - Export API Key: Before using the other KubeView CLI commands, export your API Key that you created earlier by executing:
export KUBEVIEW_API_KEY='you_api_key' - Install CLI: Install the CLI tool using npm:
npm install -g kubeview
Here are the available commands and their usage:
kubeview createEnvironment -u <username> -r <repoName> -p <pullRequest> -f <filePath> This command creates a preview environment for the specified pull request.
kubeview environment -u <username> -r <repoName> -p <pullRequest>Use this command to retrieve details about a specific preview environment for a pull request.
kubeview environments -u <username>Retrieve all environments created by the specified user.
kubeview deleteEnvironment -u <username> -r <repoName> -p <pullRequest>Delete the preview environment associated with the specified pull request.
kubeview getPodLogs -r <repo> -p <pull> -n <podName>Retrieve logs from a specific pod in the preview environment.
kubeview api-key listUse this command to list all available API keys.
curl --location 'http://localhost:8080/github/repos/{username}/{repo}/createEnvironment/{pull}' \
--header 'x-api-key: your_api_key' \
--header 'github-token: your_github_token' \
--header 'Content-Type: application/json' \
--data '{
"filePaths": []
}'This curl api can be integrated to creates a preview environment for the specified pull request.
curl --location 'http://localhost:8080/kube/environment/{username}/{repo}/{pull}' \
--header 'x-api-key: your_api_key' \
--header 'github-token: your_github_token' Use this command to retrieve details about a specific preview environment for a pull request.
curl --location 'http://localhost:8080/kube/environments/{username}' \
--header 'x-api-key: your_api_key' \
--header 'github-token: your_github_token'Retrieve all environments created by the specified user.
curl --location 'http://localhost:8080/github/repos/{username}/{repo}/deleteEnviornment/{pull}' \
--header 'x-api-key: your_api_key' \
--header 'github-token: your_github_token' Delete the preview environment associated with the specified pull request.
curl --location 'http://localhost:8080/kube/logs/{repo}/{pull}/{podName}' \
--header 'x-api-key: your_api_key' \
--header 'github-token: your_github_token' Retrieve logs from a specific pod in the preview environment.
name: Docker Build and Push
on:
pull_request:
branches:
- main
- developer
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Get commit SHA
id: commit_sha
run: echo "::set-output name=sha::$(git rev-parse HEAD)"
- name: Build Docker image
run: |
docker build -t username/imageName:tag .
- name: Push Docker image to Docker Hub
run: |
docker push username/imageName:tag
- name: Call API
run: |
curl --location 'http://backendhost:port/github/repos/{owner}/{repo}/createEnvironment/${{ github.event.pull_request.number }}' \
--header 'x-api-key: your_api_key' \
--header 'github-token: github_token' \
--header 'Content-Type: application/json' \
--data '{
"filePaths": ["/kube-deployment.yaml", "/kube-service.yaml", "/kube-pvc.yaml"]
}'