Skip to content

Commit ac1d12c

Browse files
committed
release
1 parent 67e105d commit ac1d12c

File tree

4 files changed

+179
-1
lines changed

4 files changed

+179
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
.git
3+
.DS_Store

Dockerfile

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM alpine:3.10.2
2+
MAINTAINER Serhiy Mitrovtsiy <mitrovtsiy@ukr.net>
3+
4+
LABEL name="kubectl"
5+
LABEL version="1.0.0"
6+
LABEL repository="https://github.com/exelban/gcloud"
7+
LABEL homepage="https://github.com/exelban/gcloud"
8+
LABEL maintainer="Serhiy Mytrovtsiy <mitrovtsiy@ukr.net>"
9+
10+
LABEL com.github.actions.name="Kuberentes (k8s) cli - kubectl"
11+
LABEL com.github.actions.description="GitHub Action for working with kubectl (k8s)"
12+
LABEL com.github.actions.icon="terminal"
13+
LABEL com.github.actions.color="blue"
14+
15+
ARG KUBE_VERSION="1.15.4"
16+
17+
COPY entrypoint.sh /entrypoint.sh
18+
19+
RUN chmod +x /entrypoint.sh && \
20+
apk add --no-cache --update openssl curl ca-certificates && \
21+
curl -L https://storage.googleapis.com/kubernetes-release/release/v$KUBE_VERSION/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl && \
22+
chmod +x /usr/local/bin/kubectl && \
23+
rm -rf /var/cache/apk/*
24+
25+
ENTRYPOINT ["/entrypoint.sh"]
26+
CMD ["cluster-info"]

README.md

+116-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,117 @@
11
# kubectl
2-
GitHub Action for working with kubectl (k8s)
2+
3+
[![Preview](https://serhiy.s3.eu-central-1.amazonaws.com/Github_repo/kubectl/logo.png)](https://cloud.google.com)
4+
5+
GitHub Action for working with kubectl ([k8s](https://kubernetes.io))
6+
7+
## Usage
8+
To use kubectl put this step into your workflow:
9+
10+
### Authorization with config file
11+
```yaml
12+
- uses: exelban/kubectl@master
13+
env:
14+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
15+
with:
16+
args: get pods
17+
```
18+
19+
### Authorization with credentials
20+
```yaml
21+
- uses: exelban/kubectl@master
22+
env:
23+
KUBE_HOST: ${{ secrets.KUBE_HOST }}
24+
KUBE_USERNAME: ${{ secrets.KUBE_USERNAME }}
25+
KUBE_PASSWORD: ${{ secrets.KUBE_PASSWORD }}
26+
KUBE_CERTIFICATE: ${{ secrets.KUBE_CERTIFICATE }}
27+
with:
28+
args: get pods
29+
```
30+
31+
## Environment variables
32+
All these variables need to authorize to kubernetes cluster.
33+
I recommend using secrets for this.
34+
35+
### KUBECONFIG file
36+
First options its to use [kubeconfig file](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/).
37+
38+
For this method `KUBE_CONFIG` required.
39+
You can find it: `cat $HOME/.kube/config | base64 `.
40+
41+
Optionally you can switch the [context](https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) (the cluster) if you have few in kubeconfig file. Passing specific context to `KUBE_CONTEXT`. To see the list of available contexts do: `kubectl config get-contexts`.
42+
43+
| Variable | Type |
44+
| --- | --- |
45+
| KUBE_CONFIG | string (base64) |
46+
| KUBE_CONTEXT | string |
47+
48+
### KUBECONFIG file
49+
Another way to authenticate in the cluster is [HTTP basic auth](https://kubernetes.io/docs/reference/access-authn-authz/authentication/).
50+
51+
For this you need to pass:
52+
- host (IP only, without protocol)
53+
- username
54+
- password
55+
- cluster CA certificate
56+
57+
| Variable | Type |
58+
| --- | --- |
59+
| KUBE_HOST | string |
60+
| KUBE_USERNAME | string |
61+
| KUBE_PASSWORD | string |
62+
| KUBE_CERTIFICATE | string |
63+
64+
## Example
65+
```yaml
66+
name: Get pods
67+
on: [push]
68+
69+
jobs:
70+
deploy:
71+
name: Deploy
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- uses: actions/checkout@v1
76+
- uses: exelban/kubectl@master
77+
env:
78+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
79+
with:
80+
args: get pods
81+
```
82+
83+
```yaml
84+
name: Get pods
85+
on: [push]
86+
87+
jobs:
88+
deploy:
89+
name: Deploy
90+
runs-on: ubuntu-latest
91+
92+
steps:
93+
- uses: actions/checkout@v1
94+
- uses: exelban/kubectl@master
95+
env:
96+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
97+
98+
- uses: exelban/kubectl@master
99+
with:
100+
args: get pods
101+
```
102+
103+
## Versions
104+
If you need a specific version of kubectl, make a PR with a specific version number.
105+
After accepting PR the new release will be created.
106+
To use a specific version of kubectl use:
107+
108+
```yaml
109+
- uses: exelban/kubectl@1.14.3
110+
env:
111+
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
112+
with:
113+
args: get pods
114+
```
115+
116+
## Licence
117+
[MIT License](https://github.com/exelban/kubectl/blob/master/LICENSE)

entrypoint.sh

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ ! -d "$HOME/.kube" ]; then
6+
mkdir -p $HOME/.kube
7+
fi
8+
9+
if [ ! -f "$HOME/.kube/config" ]; then
10+
if [ ! -z "${KUBE_CONFIG}" ]; then
11+
12+
echo "$KUBE_CONFIG" | base64 -d > $HOME/.kube/config
13+
14+
if [ ! -z "${KUBE_CONTEXT}" ]; then
15+
kubectl config use-context $KUBE_CONTEXT
16+
fi
17+
18+
elif [ ! -z "${KUBE_HOST}" ]; then
19+
20+
echo "$KUBE_CERTIFICATE" | base64 -d > $HOME/.kube/certificate
21+
kubectl config set-cluster default --server=https://$KUBE_HOST --certificate-authority=$HOME/.kube/certificate > /dev/null
22+
kubectl config set-credentials cluster-admin --username=$KUBE_USERNAME --password=$KUBE_PASSWORD > /dev/null
23+
kubectl config set-context default --cluster=default --namespace=default --user=cluster-admin > /dev/null
24+
kubectl config use-context default > /dev/null
25+
26+
else
27+
echo "No authorization data found. Please provide CONFIG or HTTPS variables. Exiting...."
28+
exit 1
29+
fi
30+
fi
31+
32+
echo ::add-path::/usr/local/bin/kubectl
33+
34+
kubectl $*

0 commit comments

Comments
 (0)