GitHub Action to deploy Knative Service using Knative Client.
Kubernetes Cluster with Knative, if you dont have an OpenShift cluster get one spinned instantly via try.openshift.com.
The action has the following parameters:
Name | Description | Default |
---|---|---|
service_name* |
The Knative Service Name |
|
service_namespace |
The Kubernetes Namespace to deploy to |
default |
service_operation |
The |
create |
container_image* |
The container image to use for service |
|
service_params |
The extra service parameters to pass to the service |
|
private_registry |
Whether the image is pushed to private registry. Possible values yes or no |
yes |
registry_user |
The registry user to use to create image pull secret.Required if private_registry is yes. |
|
registry_password |
The registry user credentials. Required if private_registry is yes. |
Marked * are required attributes
Name | Description |
---|---|
service_url |
Knative Service URL of the service created |
Note
|
When The secret will be created in |
-
Create the following GitHub Secrets in your GitHub repository:
-
Container registry access e.g GitHub Container Registry where you push built images.
As the examples show using GitHub Container registry create the following secret and add to your repository:
GHCR_PAT
- The GithHub PAT to allow pushing built image into GitHub Container registry .
If you are using other Container registries you might need to add extra secrets to your repository typically for your registry username and password.
As OpenShift is used as the Kubernetes platform in the example, you can use the oc-login action,to login into the OpenShift cluster to perform kn
actions.
# Login into the OpenShift cluster with your OpenShift username
# and password
- name: Login into OpenShift Cluster
id: oc_login
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_username: ${{ secrets.OPENSHIFT_USERNAME }}
openshift_password: ${{ secrets.OPENSHIFT_PASSWORD }}
# With successful login in previous step, do the kn action
- name: Knative Service Deploy
id: kn_service_deploy
uses: kameshsampath/kn-service-action
with:
service_name: fruits-app
service_namespace: demos
container_image: "ghcr.io/kameshsampath/fruits-app@${{ steps.docker_build_push.outputs.digest }}"
registry_user: "${{ github.repository_owner }}"
registry_user: "${{ secrets.GHCR_PAT }}"
The above action configuration will be interpreted in to kn
command like:
kn service create fruits-app \
--namespace=demos \
--image=ghcr.io/kameshsampath/fruits-app@sha256:b38df3a060b6eb5c9cb4d4fba4deecba4abc5f97f6db0f5d6a04109bf1e8fe79 \
--pull-secret=ghcr.io.pull-secret
The service action provides basic options such namespace, service name, image and operation to be configured. There might be cases where you might want to pass extra arguments to the kn service <command>
, in those cases you can use service_params
as shown:
Consider an example that you want to add --max-scale=5
and --min-scale=1
, then your action snippet will be:
- name: Knative Service Deploy
id: kn_service_deploy
uses: kameshsampath/kn-service-action
with:
service_name: fruits-app
service_namespace: demos
private_registry: no
container_image: "docker.io/kameshsampath/fruits-app@${{ steps.docker_build_push.outputs.digest }}"
service_params: >
--max-scale=5
--min-scale=1
The above action configuration will be interpreted in to kn
command like:
kn service create fruits-app --namespace=demos --image=docker.io/kameshsampath/fruits-app@sha256:b38df3a060b6eb5c9cb4d4fba4deecba4abc5f97f6db0f5d6a04109bf1e8fe79 --max-scale=5 --min-scale=1
For a complete action example check kn-service-action-example.