Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mp-es/k8s-deploy
Action that deploys an application in an On-Premises Kubernetes cluster based in a GitOps repository.
https://github.com/mp-es/k8s-deploy
github-actions gitops hacktoberfest k8s k8s-deploy kubernetes premises-kubernetes-cluster
Last synced: about 1 month ago
JSON representation
Action that deploys an application in an On-Premises Kubernetes cluster based in a GitOps repository.
- Host: GitHub
- URL: https://github.com/mp-es/k8s-deploy
- Owner: MP-ES
- Created: 2021-04-20T19:28:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-09-13T21:21:14.000Z (3 months ago)
- Last Synced: 2024-10-15T16:02:07.023Z (2 months ago)
- Topics: github-actions, gitops, hacktoberfest, k8s, k8s-deploy, kubernetes, premises-kubernetes-cluster
- Language: Go
- Homepage:
- Size: 124 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# k8s-deploy
Action that deploys an application in an On-Premises Kubernetes cluster based in a GitOps repository.
[![Codecov](https://codecov.io/gh/MP-ES/k8s-deploy/graph/badge.svg?token=HSN90LV4NG)](https://codecov.io/gh/MP-ES/k8s-deploy)
[![Integration](https://github.com/MP-ES/k8s-deploy/workflows/Integration/badge.svg)](https://github.com/MP-ES/k8s-deploy/actions?query=workflow%3AIntegration)
[![Release](https://github.com/MP-ES/k8s-deploy/workflows/Release/badge.svg)](https://github.com/MP-ES/k8s-deploy/actions?query=workflow%3ARelease)## Requirements
The owner must have a repository named **gitops** with the rules of application deployment. For example, if you are deploying the repository **ORG/application**, then this k8s-deploy will try to get the rules in the repository **ORG/gitops**, once the repository owner is **ORG**.
## Usage
```yaml
- name: Deploy on on-premises K8S
uses: MP-ES/k8s-deploy@v2
with:
# Multiline input where each line contains the name of a Kubernetes environment defined in the GitOps repository
k8s_envs: |
env1
env2# Path to the manifest directory, with files to be used for deployment
# DEFAULT: kubernetes
manifest_dir: kubernetes# Personal access token (PAT) used to manage comments on pull request
# DEFAULT: ${{ github.token }}
repo_token: ${{ github.token }}# GitHub PAT with read permission on gitOps repository, if gitOps is private
gitops_token: ${{ secrets.SECRET_NAME }}# Deployment strategy to be used. Allowed values are none, canary and blue-green
# More details below
# DEFAULT: none
strategy: noneenv:
# list of app secrets, defined in gitOps repository
app_secret1: ${{ secrets.app_secret1 }}
app_secret2: ${{ secrets.app_secret2 }}# base64 of kubeconfig file for each Kubernetes environment defined in k8s_envs
# See below an example of an expected kubeconfig
base64_kubeconfig_env1: ${{ secrets.base64_kubeconfig_env1 }}
base64_kubeconfig_env2: ${{ secrets.base64_kubeconfig_env2 }}
```### Strategy
Deployment strategy to be used while applying manifest files on the cluster. Acceptable values are none, canary and blue-green.
#### none
No deployment strategy is used when deploying. The files are changed on the cluster in force mode. This is sufficient to pull requests deployments or if the application can have short downtime during deployment.
#### canary
*not implemented yet.*
#### blue-green
*not implemented yet.*
### kubeconfig example
The most important part is the **context name**, which **must be** the same as the **Kubernetes environment name** to which the kubeconfig belongs.
```yaml
apiVersion: v1
kind: Config
clusters:
- cluster:
certificate-authority-data: base64-encoded of ca-file
server: https://server.domain.com:6443
name: k8s-cluster
users:
- name: kube-admin-user
user:
client-certificate-data: base64-encoded of cert-file
client-key-data: base64-encoded of key-file
contexts:
- context:
cluster: k8s-cluster
user: kube-admin-user
name: env1
```You can generate a base64 of the file with `base64 -w 0 kubeconfig_file.yaml`.
## Outputs
Following outputs are available:
| Name | Type | Description |
| -------- | ----------- | --------------------------------------------- |
| `status` | JSON object | Array of deployment status by K8S environment |Output example:
```json
[
{
"K8sEnv":"dev",
"Deployed":true,
"ErrMsg":"",
"DeploymentLog":"deployment.apps/test created\nservice/test created\ningress.extensions/test created\nnamespace/test unchanged\nresourcequota/test unchanged\nsecret/test unchanged\n",
"Ingresses":[
"ingress.env.domain.com"
]
},
{
"K8sEnv":"app",
"Deployed":false,
"ErrMsg":"1 error occurred:\n\t* exit status 1\n\n",
"DeploymentLog":"resourcequota/test created\nsecret/test created\nError from server (NotFound): error when creating \"../.deploy/pr/final.yaml\": namespaces \"test\" not found\n",
"Ingresses":[]
}
]
```## Developer
```shell
# Copy .env.* example file to .env file
# Simulate a pull request call
cp src/.env.pr src/.env# Install lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -c 'sh -s -- -b /usr/local/bin'# Run lint locally
# From src directory
golangci-lint run# Run tests
# From src directory
go test -race -v -covermode=atomic -coverprofile=coverage.out ./...# See cover report
# From src directory
go tool cover -html=coverage.out
```### Update dependencies
```shell
cd src# Update dependencies
go get -u# Update go.mod
go mod tidy
```