Add support for IBM Kuberenetes Service (IKS)

This patch adds support for deploying an application to IKS
by performing the following steps:

1. Downloading and installing the IBM Cloud CLI,
2. Building locally with Docker,
3. Pushing to ICR (IBM Container Registry), and
4. Deploying with kubectl to IKS

Co-authored-by: JJ Asghar <jjasghar@gmail.com>

Signed-off-by: Steve Martinelli <s.martinelli@gmail.com>
This commit is contained in:
Steve Martinelli
2020-04-24 23:48:32 -04:00
parent 8c4fc57de8
commit 0254a244d2
3 changed files with 141 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
# This workflow will build a docker container, publish it to IBM Container Registry, and deploy it to IKS when a release is created
#
# To configure this workflow:
#
# 1. Ensure that your repository contains a Dockerfile
# 2. Setup secrets in your repository by going to settings: Create ICR_NAMESPACE and IBM_CLOUD_API_KEY
# 3. Change the values for the IBM_CLOUD_REGION, REGISTRY_HOSTNAME, IMAGE_NAME, IKS_CLUSTER, DEPLOYMENT_NAME, and PORT
name: Build and Deploy to IKS
on:
release:
types: [created]
# Environment variables available to all jobs and steps in this workflow
env:
GITHUB_SHA: ${{ github.sha }}
IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }}
IBM_CLOUD_REGION: us-south
ICR_NAMESPACE: ${{ secrets.ICR_NAMESPACE }}
REGISTRY_HOSTNAME: us.icr.io
IMAGE_NAME: iks-test
IKS_CLUSTER: example-iks-cluster-name-or-id
DEPLOYMENT_NAME: iks-test
PORT: 5001
jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
# Download and Install IBM Cloud CLI
- name: Install IBM Cloud CLI
run: |
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
ibmcloud --version
ibmcloud config --check-version=false
ibmcloud plugin install -f kubernetes-service
ibmcloud plugin install -f container-registry
# Authenticate with IBM Cloud CLI
- name: Authenticate with IBM Cloud CLI
run: |
ibmcloud login --apikey "${IBM_CLOUD_API_KEY}" -r "${IBM_CLOUD_REGION}" -g default
ibmcloud cr region-set "${IBM_CLOUD_REGION}"
ibmcloud cr login
# Build the Docker image
- name: Build with Docker
run: |
docker build -t "$REGISTRY_HOSTNAME"/"$ICR_NAMESPACE"/"$IMAGE_NAME":"$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" .
# Push the image to IBM Container Registry
- name: Push the image to ICR
run: |
docker push $REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$GITHUB_SHA
# Deploy the Docker image to the IKS cluster
- name: Deploy to IKS
run: |
ibmcloud ks cluster config --cluster $IKS_CLUSTER
kubectl config current-context
kubectl create deployment $DEPLOYMENT_NAME --image=$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$GITHUB_SHA --dry-run -o yaml > deployment.yaml
kubectl apply -f deployment.yaml
kubectl rollout status deployment/$DEPLOYMENT_NAME
kubectl create service loadbalancer $DEPLOYMENT_NAME --tcp=80:$PORT --dry-run -o yaml > service.yaml
kubectl apply -f service.yaml
kubectl get services -o wide
+6
View File
@@ -0,0 +1,6 @@
{
"name": "Build and Deploy to IKS",
"description": "Build a docker container, publish it to IBM Container Registry, and deploy to IKS.",
"iconName": "ibm",
"categories": null
}
+61
View File
@@ -0,0 +1,61 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg version="1.0" xmlns="http://www.w3.org/2000/svg"
width="3200.000000pt" height="1500.000000pt" viewBox="0 0 3200.000000 1500.000000"
preserveAspectRatio="xMidYMid meet">
<metadata>
Created by potrace 1.16, written by Peter Selinger 2001-2019
</metadata>
<g transform="translate(0.000000,1500.000000) scale(0.100000,-0.100000)"
fill="#000000" stroke="none">
<path d="M17693 7818 c2 -1280 4 -1367 21 -1423 46 -152 139 -269 258 -325
118 -55 164 -62 411 -67 l227 -5 0 246 0 246 -140 0 -140 0 0 1345 0 1345
-320 0 -320 0 3 -1362z"/>
<path d="M25360 8530 c0 -357 -3 -650 -8 -650 -4 0 -21 30 -36 66 -59 134
-159 235 -299 298 -107 49 -166 61 -302 60 -450 -3 -724 -268 -820 -794 -26
-141 -32 -517 -11 -676 41 -310 127 -514 282 -670 65 -65 98 -89 176 -128 211
-104 478 -115 673 -26 137 62 260 188 306 313 12 31 26 57 30 57 5 0 9 -85 9
-190 l0 -190 320 0 320 0 0 1590 0 1590 -320 0 -320 0 0 -650z m-228 -768
c109 -39 194 -122 219 -214 6 -24 9 -187 7 -441 l-3 -402 -27 -51 c-62 -118
-202 -188 -378 -187 -146 0 -259 57 -337 171 -73 107 -76 127 -81 464 -4 324
1 366 54 472 47 94 144 175 243 203 67 19 232 11 303 -15z"/>
<path d="M15905 9034 c-493 -76 -839 -381 -999 -880 -109 -341 -125 -821 -41
-1196 92 -408 319 -718 639 -873 203 -98 359 -130 636 -130 210 0 292 12 440
62 270 92 498 294 649 573 l40 76 -252 146 c-138 81 -259 149 -268 153 -12 4
-20 -5 -33 -39 -28 -73 -107 -186 -172 -246 -176 -163 -465 -198 -702 -85 -85
40 -191 139 -236 220 -42 76 -83 210 -95 310 -14 114 -14 633 -1 745 46 380
276 600 630 600 240 0 407 -97 505 -292 25 -50 45 -96 45 -104 0 -8 4 -14 10
-14 7 0 544 275 559 286 2 2 -18 42 -43 91 -191 358 -474 553 -871 602 -120
15 -329 12 -440 -5z"/>
<path d="M6000 8850 l0 -150 210 0 210 0 0 -1200 0 -1200 -210 0 -210 0 0
-150 0 -150 600 0 600 0 0 150 0 150 -210 0 -210 0 0 1200 0 1200 210 0 210 0
0 150 0 150 -600 0 -600 0 0 -150z"/>
<path d="M7860 7500 l0 -1501 748 3 c672 3 753 5 807 21 278 80 499 328 559
627 73 367 -35 667 -299 828 -59 36 -191 82 -234 82 -48 0 -38 26 15 39 191
48 337 186 400 378 27 83 29 98 29 253 0 189 -11 243 -77 380 -33 68 -57 100
-127 170 -97 97 -194 152 -336 192 -79 22 -91 22 -782 26 l-703 3 0 -1501z
m1338 1165 c168 -40 275 -152 301 -316 14 -81 14 -236 1 -314 -13 -80 -61
-174 -111 -220 -54 -49 -148 -92 -229 -104 -38 -6 -249 -11 -502 -11 l-438 0
0 490 0 490 458 0 c368 0 469 -3 520 -15z m70 -1290 c181 -43 299 -162 332
-334 13 -69 13 -302 0 -371 -32 -171 -153 -293 -331 -335 -52 -12 -153 -15
-556 -15 l-493 0 0 535 0 535 493 0 c401 0 504 -3 555 -15z"/>
<path d="M10670 7500 l0 -1500 175 0 175 0 0 1260 c0 1008 3 1260 13 1260 7 0
56 -89 110 -197 132 -266 860 -1603 869 -1595 19 20 739 1344 844 1555 68 136
129 247 134 247 7 0 10 -432 10 -1265 l0 -1265 175 0 175 0 0 1500 0 1500
-236 -2 -236 -3 -431 -808 c-238 -444 -436 -806 -440 -804 -4 1 -200 364 -436
807 l-428 805 -237 3 -236 2 0 -1500z"/>
<path d="M19753 8300 c-302 -38 -545 -182 -702 -413 -238 -350 -268 -982 -67
-1393 136 -276 360 -454 656 -519 103 -22 324 -30 433 -16 478 64 790 387 872
901 22 140 22 400 0 540 -65 408 -282 704 -611 832 -42 16 -116 38 -163 49
-101 22 -314 32 -418 19z m338 -533 c96 -46 163 -134 194 -254 19 -72 22 -670
4 -755 -43 -204 -210 -325 -423 -305 -143 13 -241 79 -301 200 -50 102 -58
179 -53 529 4 268 6 299 26 360 29 85 76 153 136 195 74 51 125 63 251 60 96
-3 117 -6 166 -30z"/>
<path d="M21393 7443 c3 -783 4 -822 24 -908 60 -262 172 -424 356 -515 115
-57 202 -73 357 -67 98 4 142 10 206 31 156 50 279 158 355 311 23 47 46 85
51 85 4 0 8 -85 8 -190 l0 -190 315 0 315 0 0 1130 0 1130 -315 0 -315 0 0
-753 c0 -826 1 -811 -60 -894 -66 -89 -195 -145 -340 -146 -158 -1 -251 66
-301 218 -10 31 -15 206 -19 805 l-5 765 -318 3 -318 2 4 -817z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.7 KiB