Git Product home page Git Product logo

kubernetestask's Introduction

Kubernetes extension for VSTS

Build Status

Enable us to use Kubernetes related product for VSTS. Also it enable us to kubernetes endpoint for kubectl. You can use kubectl, helm, and istioctl by this extension. This task aims for using Linux Hosted Agent(preview). GitHub repo is here.

NOTE: this task is NOT the official Kubernetes task created by Microsoft.

Currently you can use istio/helm feature from 3.0.0. or later.

Header

1. How to use

1.1. Create an endpoint

Choose Kubernetes endpoint

Choose Kubernetes endpoint.

Kubernetes Endpoint

Set your endpoint

Kubernetes Connection pops up. Then fill the box.

Kubernetes Connection

  • Connection name: Endpoint name (Anything is OK)
  • Server URL : K8s Cluster URL for memo (Not used for the task until now)
  • kubeconfig : Copy & paste your config file

You can get config file from your k8s master node .kube/config. See Microsoft Azure Container Service Engine - Kubernetes Walkthrough Then copy the file content and paste on kubeconfig column.

NOTE:

If you copy config file into Kubeconfig, the build log of VSTS might show you the contents. This happens when you copy multiline. Kubernetes tasks support base64 encoding for Kubeconfig column. If you want to avoid this problem, you can convert your config file into base64 string. You can find the tool for converting config file. tools/convert.ts

Usage

your config file should be LF not CRLF if you want to use on Linux hosted build.

tsc -p .
node tools/convert.js {filename}

You can find {filename}_new file which include base64 encoding string.

1.2. downloader

If you want to use kubectl/istioctl/helm binary, you need to use this task in advance. For the backword compatibility, I letf the old tasks like kubernetes apply task and kubernetes general task. However, I recommend to use the new task with downloader. It will be much more flexible and simple.

If you use this downlaoder, you can avoid to download the binary several times. This task download kubectl/istioctl/helm binary into ./.vstsbin directory and add it to the PATH environment variables. Also, it set KUBECONFIG environment variables. If you use this downloader, the following task can use kubectl/istioctl/helm command without specifying the full-path binary file name.

downloader

  • Display Name: Name of the task
  • k8s endpoint: select the endpoint which you created at 1.1. Create an endpoint
  • kubectl binary: Leave it blank. Don't use this.(depricated)
  • kubectl download version:If you want to specify the version, fill this, e.g. v1.5.2. Blank means latest.
  • enable istioctl: Check it if you want to use istioctl
  • istioctl download version: Specify the version. Blank doesn't mean the latest. not like the kubectl downloader. e.g. 0.1.5
  • enable helm: Check it if you want to use helm
  • helm download version: Specify the version. Blank doesn't mean the latest. not like the kubectl downloader. e.g. 2.4.1

1.3. kubectl task

You can execute kubectl using this task. If you want to use this task, you need to use downloader task in advance. See 1.2. downloader.

kubectl task

  • Display name: Name of the task
  • Sub Command: Specify kubectl sub command like apply, get, and so on. Refer the Overview of kubectl.
  • Argument: You can use any options and arguments. You can specify these with a space or a new line. New line will be converted into a space.

1.4. istio task

You can execute istioctl using this task. If you want to use this task, you need to use downloader task in advance. See 1.2. downloader.

istio task

  • Display name: Name of the task
  • Sub Command: Specify istio sub command like replace, create, and so on. Refer the istioctl.
  • Argument: You can use any options and arguments. You can specify these with a space or a new line. New line will be converted into a space.

1.5. helm task

You can execute helm using this task. If you want to use this task, you need to use downloader task in advance. See 1.2. downloader.

helm task

  • Display name: Name of the task
  • Sub Command: Specify helm sub command like create, verify, and so on. Refer the Using helm.
  • Argument: You can use any options and arguments. You can specify these with a space or a new line. New line will be converted into a space.

1.6. kubernetes apply task

NOTE: kubernetes apply/general task is for backward compatibility.

1.6.1. Store and link kubectl command link with VSTS private repository (Optional)

If you use ver 2.0, you don't need this operation. However, this operation could fasten your pipeline without downloading a kubectl binary.

Link your repo which has kubecntl command.

Link Artifact

Please chmod +x kubectl before adding kubectl to your repo.

VSTS Private Repository

1.6.2. Setup your kubectlapply task

Then you can use the endpoint, specify the kubectl command and YAML file for deployment. Internally, it calls kubectl apply command.

kubectlapply Task

If you want to change the YAML file dynamically, you can use Replace tokens on the VSTS Marketplace.

You can see the downloadVersion textbox. If you don't specify KubectlBinary, this task automatically download the latest kubebinary. If you want to specify the version, fill the downloadVersion, e.g. v1.5.2.

1.7. kubernetes general task

NOTE: kubernetes apply/general task is for backward compatibility.

You can use every kubectl command you want. Use kubectlgeneral task. You can specify a lot of arguments separated with space or new line.

kubectlgeneral Task

You can see the downloadVersion textbox. If you don't specify KubectlBinary, this task automatically download the latest kubebinary. If you want to specify the version, fill the downloadVersion, e.g. v1.5.2.

2. Contribution

This is the guide for the contribution. Feel free to contribute for this task.

2.1. Goal of this task

A kubernetes task for any platform.

This project is started before the official kubernetes task for vsts. I develop this task with a vsts production team members. With some of the feed back the official task has been launched. However, the official task is tightly coupled with ACS (Azure Container Service). Some people use this task for GCP and OnPrem.

A kubernetes task for incubetion and feedback.

I'll add some new feature like istio/helm integration in advance as a incubetion project. I'll send the feedback to the production team.

2.2. Prerequisite

You need typings / tsc / tfx commands.

Please refer these to install.

npm install
npm install [email protected]  --global-style
npm install [email protected] --global-style
npm install [email protected]  --global-style

FYI: typings tfx-cli typescript

2.3. Build the extension

I tested via windows environment.

npm test               // Compile Typescript and Test these
npm run deploy         // Deploy kubectl and node_modules into task directory
npm run build          // Build *.vsix file

If you want to debug these. NOTE: I'm using GitBash for this developmnet. You can see the debug output.

 export TASK_TEST_TRACE=1

2.4. Upload to the market place

Go to the Market place Market Place Manage Then upload and share with your VSTS account. Tsuyoshi Ushio's publisher site

Stable version is 1.0.0 or later. You can test it make it 0.x.x with preview tag.

2.5. Current road map

Now I just start this project. Just initial commit. However, you can see the image of the endpoint and build task.

  1. Flexbile Command Excecution except for kubectl apply
  2. Enable to select the version of kubectl and automatically installed.

2.6. Version management

We need to test this plugin in VSTS before rolling out. However, if we want to test this, we need to deploy to the Marketplace. If we create a new feature, the task version will be the next major version. However, we might upgrade vss-extension.json's version. I'm showing you an example.

Current task version: v1.0.0 
Current vss-extension version: v1.0.0 

If you want to develop a new feature, you can deploy to the Marketplace using these versions.

Task version: v2.0.0 (with preview tag)
Vss-extension version: v1.0.1

In this case, customer environment won't be influenced by this release. They keep on using v1.0.0 If I choose v2.0.0 Preview intendedly, we can change the version. Since this feature might be preview in VSTS, this spec might change in the future.

7 Resources

Step by Step: Node Task with Typescript API

kubernetestask's People

Contributors

anthonychu avatar ctorrao avatar ericsciple avatar rakelkar avatar rakelkar-msft avatar takeruushio avatar tsuyoshiushio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

kubernetestask's Issues

Unable to update Endpoint service in VSTS

Downloaded the Kubeconfig and when trying to update the KubeConfig contents to the VSTS Endpoint service getting the below error,
"The Kubconfig does not contain user field. Please check the kubeconfig. "
( we have verified that the user field exist)

Kindly help to resolve this. we were able to use the same VSTS-Kubernetes a month back.

Support JsonPath in output

Now the Output only supports -o yaml and -o json, yet how about also support customized output instead of a drop-down?
Like I need to track kubernetes' deployment status by fetching unavalableReplicas from status as below
-o=jsonpath='{$.status.unavailableReplicas}' --namespace=$(env)

error: unable to parse "\"$(cat": yaml"

when I use basic commnad kubectl patch, I have this parsing error .

subcommand : patch
arguments : deploy/poc-ci-deployment --patch "$(cat patch.json)" -v=8

2018-05-07T14:59:50.6298360Z ##[debug]exec tool: .vstsbin/kubectl.v1.8.4
2018-05-07T14:59:50.6720260Z ##[debug]arguments:
2018-05-07T14:59:50.7136380Z ##[debug] patch
2018-05-07T14:59:50.8420900Z ##[debug] deploy/poc-ci-deployment
2018-05-07T14:59:50.8831890Z ##[debug] --patch
2018-05-07T14:59:50.9222310Z ##[debug] "$(cat
2018-05-07T14:59:50.9611450Z ##[debug] patch.json)"
2018-05-07T14:59:51.0000820Z ##[debug] -v=8
2018-05-07T14:59:51.0396980Z ##[debug] --kubeconfig
2018-05-07T14:59:51.0812400Z ##[debug] ./kubeconfig
2018-05-07T14:59:51.1082100Z [command] .vstsbin/kubectl.v1.8.4 patch deploy/poc-ci-deployment --patch "$(cat patch.json)" -v=8 --kubeconfig ./kubeconfig
2018-05-07T14:59:51.1348160Z I0507 14:59:47.858994 126502 loader.go:357] Config loaded from file ./kubeconfig
2018-05-07T14:59:51.1607420Z F0507 14:59:47.859132 126502 helpers.go:120] error: unable to parse ""$(cat": yaml: found unexpected end of stream

It works on Shell though

Add output mode 'name'?

I am unable to use kubectl delete to remove resources using this task since it give the following error:

##[error]error: Unexpected -o output mode: json. We only support '-o name'.

The problem is we only have the options: json and yaml for the output format. It seems kubernetes requires you to use 'name' as the output mode when you delete resources.

Can't use kubectl exec with --

When I try this command via kubectlgeneral command, I specify these.

SubCommand: exec
Arguments: mongo-2180634381-zx0d3 --namespace mrp -- mongo ordering /tmp/MongoRecords.js

However, I've got error. This might because, --kubeconfig coming after the --

2017-02-19T16:30:20.9932090Z [command]/opt/vsts/work/r1/a/MicroservicesK8s/kubectl exec mongo-2180634381-zx0d3 --namespace mrp -- mongo ordering /tmp/MongoRecords.js --kubeconfig ./config
2017-02-19T16:30:21.0184050Z The connection to the server localhost:8080 was refused - did you specify the right host or port?
2017-02-19T16:30:21.0756140Z ##[error]Error: /opt/vsts/work/r1/a/MicroservicesK8s/kubectl failed with return code: 1
2017-02-19T16:30:21.1543870Z ##[section]Finishing: kubectlgeneral 

It works when I try this via command line.

./kubectl exec mongo-2180634381-zx0d3 --namespace mrp -- mongo orderi
ng /tmp/MongoRecords.js
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017/ordering
MongoDB server version: 3.4.2

Fails to download helm since Dec 03 2017

Since yesterday we've had a bunch of failed builds, apparently because the helm downloader stage is failing on an unhandled promise rejection.

The helm version we've been targeting is 2.6.0, which is the one we started seeing the failure on yesterday. Attempting to specify 2.7.0 leads to the same - these versions appear to be available on the URI found in this project.

Here's a VSTS build log

2017-12-04T08:03:17.2709670Z ##[section]Starting: Download helm, kubectl
2017-12-04T08:03:17.4222800Z ==============================================================================
2017-12-04T08:03:17.4556950Z Task         : k8s downloader
2017-12-04T08:03:17.4889170Z Description  : Download the kubectl, istioctl, and helm. Also It enable to use these command.
2017-12-04T08:03:17.5228590Z Version      : 1.0.3
2017-12-04T08:03:17.5565870Z Author       : Tsuyoshi Ushio
2017-12-04T08:03:17.5900520Z Help         : See [Kubernetes task](https://github.com/TsuyoshiUshio/KubernetesTask)
2017-12-04T08:03:17.6239430Z ==============================================================================
2017-12-04T08:03:21.9552420Z [command]curl -L https://storage.googleapis.com/kubernetes-release/release/stable.txt
2017-12-04T08:03:21.9974110Z   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2017-12-04T08:03:22.0386600Z                                  Dload  Upload   Total   Spent    Left  Speed
2017-12-04T08:03:22.0597370Z 
2017-12-04T08:03:22.1011260Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2017-12-04T08:03:22.1658450Z 100     7  100     7    0     0     12      0 --:--:-- --:--:-- --:--:--    12
2017-12-04T08:03:22.2258960Z 100     7  100     7    0     0     12      0 --:--:-- --:--:-- --:--:--    12
2017-12-04T08:03:22.2840630Z v1.8.4
2017-12-04T08:03:22.5131140Z [command]mkdir -p /vsts/agent/_work/1/s/.vstsbin
2017-12-04T08:03:22.8566860Z [command]curl -L -o /vsts/agent/_work/1/s/.vstsbin/kubectl.v1.8.4 https://storage.googleapis.com/kubernetes-release/release/v1.8.4/bin/linux/amd64/kubectl
2017-12-04T08:03:22.8997790Z   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2017-12-04T08:03:22.9389170Z                                  Dload  Upload   Total   Spent    Left  Speed
2017-12-04T08:03:22.9582990Z 
2017-12-04T08:03:22.9979120Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2017-12-04T08:03:23.7900820Z   8 49.9M    8 4112k    0     0  4316k      0  0:00:11 --:--:--  0:00:11 4314k
2017-12-04T08:03:23.9951980Z  86 49.9M   86 43.1M    0     0  23.2M      0  0:00:02  0:00:01  0:00:01 23.2M
2017-12-04T08:03:24.0555920Z 100 49.9M  100 49.9M    0     0  24.2M      0  0:00:02  0:00:02 --:--:-- 24.2M
2017-12-04T08:03:24.3469710Z [command]chmod 777 /vsts/agent/_work/1/s/.vstsbin/kubectl.v1.8.4
2017-12-04T08:03:24.6817300Z [command]cp /vsts/agent/_work/1/s/.vstsbin/kubectl.v1.8.4 /vsts/agent/_work/1/s/.vstsbin/kubectl
2017-12-04T08:03:25.1024370Z [command]/bin/bash .helmdownloader.sh
2017-12-04T08:03:26.3742110Z   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2017-12-04T08:03:26.4329710Z                                  Dload  Upload   Total   Spent    Left  Speed
2017-12-04T08:03:26.4600460Z 
2017-12-04T08:03:26.5104660Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2017-12-04T08:03:26.5620920Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2017-12-04T08:03:26.6126260Z  54 11.6M   54 6480k    0     0  5542k      0  0:00:02  0:00:01  0:00:01 5543k
2017-12-04T08:03:26.6635710Z 100 11.6M  100 11.6M    0     0  7953k      0  0:00:01  0:00:01 --:--:-- 7949k
2017-12-04T08:03:26.7145900Z cp: omitting directory 'kubernetes/helm'
2017-12-04T08:03:26.7635960Z (node:27869) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Failed to exec the .helmdownloader.sh which is helm downloader.

Kubernetes task on VSTS:"Error:spawn EACCES"

Hello,

I am trying to deploy docker image to kubernetes on VSTS for CD/CI pipeline. To start with I am testing for simple get command. I have given all the required details to fill the selection. Docker Container Registry Details, cluster details. and selected "get" command and passed "pods" as arguments. I end up getting this error. "Error: spawn EACCES".

Thanking You in Advance!

image

Problems with parsing jsonpaths containing spaces

2018-09-28T16:31:37.1906338Z [command]/home/vsts/work/r1/a/.vstsbin/kubectl.v1.12.0 get pods -o=jsonpath="{range .items[?(@.metadata.labels.app == \"blahblahblah\")]}{.metadata.name}{\"\n\"}{end}" --kubeconfig ./kubeconfig
2018-09-28T16:31:38.3342543Z error: error parsing jsonpath "{range, unclosed action

Have tried numerous combinations of single quotes, double quotes and escaped versions

Download Feature fail

My customer try the download feature. However it fails by permission denied.
I guess the root cause is writing the kubectl binary on the /usr/bin
I recommend to download the current dir or staging dir and use it.

2017-04-27T07:03:42.6600595Z [command]curl -L https://storage.googleapis.com/kubernetes-release/release/stable.txt
2017-04-27T07:03:43.3733719Z v1.6.2
2017-04-27T07:03:43.3733719Z   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2017-04-27T07:03:43.3733719Z                                  Dload  Upload   Total   Spent    Left  Speed
2017-04-27T07:03:43.3733719Z 
2017-04-27T07:03:43.3733719Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
2017-04-27T07:03:43.3733719Z 100     7  100     7    0     0     29      0 --:--:-- --:--:-- --:--:--    31
2017-04-27T07:03:43.3733719Z [command]curl -L -o /usr/bin/kubectl.v1.6.2 https://storage.googleapis.com/kubernetes-release/release/v1.6.2/bin/linux/amd64/kubectl
2017-04-27T07:03:43.3890448Z   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
2017-04-27T07:03:43.3890448Z                                  Dload  Upload   Total   Spent    Left  Speed
2017-04-27T07:03:43.3890448Z 
2017-04-27T07:03:43.5765035Z   0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: Failed to create the file /usr/bin/kubectl.v1.6.2: Permission denied
2017-04-27T07:03:43.5765035Z 
2017-04-27T07:03:43.5765035Z   0 67.4M    0   629    0     0   3261      0  6:01:21 --:--:--  6:01:21  3310
2017-04-27T07:03:43.5765035Z curl: (23) Failed writing body (0 != 629)
2017-04-27T07:03:43.5921035Z ##[error]Error: curl failed with return code: 23
2017-04-27T07:03:43.5921035Z ##[section]Finishing: kubectlapply 
2017-04-27T07:03:43.5921035Z ##[section]Finishing: Release

kubectl apply failed for version 0.1.31

I released version 0.1.31 however, it failed. Now I deploy 0.1.32 to revert the change. it works.
However, 0.1.31 is added a feature for automated dowonload. I need to fix this problem.
Now I release this version instead.

https://github.com/TsuyoshiUshio/KubernetesTask/tree/fix/cannotusedoubleminus

2017-03-20T13:55:28.9681690Z ##[section]Starting: kubectlapply 
2017-03-20T13:55:30.1279490Z ==============================================================================
2017-03-20T13:55:30.1534400Z Task         : Kubernetes Apply Task
2017-03-20T13:55:30.1815740Z Description  : Kubernetes Task. You can use kubectl apply by this command.
2017-03-20T13:55:30.2054020Z Version      : 0.1.31
2017-03-20T13:55:30.2310690Z Author       : Tsuyoshi Ushio
2017-03-20T13:55:30.2543460Z Help         : Kubernetes task
2017-03-20T13:55:30.2774970Z ===================================================================
    :
2017-03-20T13:55:33.2545400Z ##[error]Error: Not found configFile: ./kubeconfig
2017-03-20T13:55:33.3339500Z ##[section]Finishing: kubectlapply 

Simply this is because it can't find .kubeconfig

Only the difference of this line

works

didn't work

istioctl not found in path

when the "kubectl binary" field is set, istioctl is not found.
It looks like you need to add the PATH for istioctl in this case

Node 6 deprecation warning

Pipelines using these tasks are seeing this warning:

##[warning]This task uses Node 6 execution handler, which will be deprecated soon. If you are the developer of the task - please consider the migration guideline to Node 10 handler - https://aka.ms/migrateTaskNode10. If you are the user - feel free to reach out to the owners of this task to proceed on migration.

Endpoint auth data not present while running the kubectl apply task

While attempting to run kubectl apply from VSTS I'm getting the following:

413031Z ##[error]Endpoint auth data not present: 33b867a8-43f0-45ca-a41e-e5dd092fdbf2
2017-10-15T21:56:42.4443028Z ##[section]Finishing: [kubectl] apply (deployment)

Can you explain what does this error represent? I believe I've added the kubernetes service connection properly.

/Maciej

Task succeeds even if operation fails

Executing a command, e.g. helm install, that fails and returns a non 0 return value will not make the task fail.
I believe the following code should be added to execCommand in base.ts (don't have permission to send a pull request):
let r = binary.execSync();
if (r.code != 0){
throw r.error
}

Error: Spawn UNKOWN

I am running into a problem with the kubernetes task. Quite frequently I receive an error Spawn UNKOWN.
The task doesn't always fail, but it does so quite frequently.

Do you have any idea what might cause the problem?

2017-06-16T09:32:59.5621981Z ##[section]Starting: kubectl apply
2017-06-16T09:32:59.5631815Z ==============================================================================
2017-06-16T09:32:59.5631815Z Task         : Deploy to Kubernetes
2017-06-16T09:32:59.5631815Z Description  : Deploy, configure, update your Kubernetes cluster in Azure Container Service by running kubectl commands.
2017-06-16T09:32:59.5631815Z Version      : 0.1.2
2017-06-16T09:32:59.5631815Z Author       : Microsoft Corporation
2017-06-16T09:32:59.5631815Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=846415)
2017-06-16T09:32:59.5641828Z ==============================================================================
2017-06-16T09:32:59.9501814Z 64788582-b6e6-49a5-a731-2a1c46e9ebb0 exists true
2017-06-16T09:33:00.6651809Z ##[error]Error: spawn UNKNOWN
2017-06-16T09:33:00.6721809Z ##[section]Finishing: kubectl apply

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.