Skip to content

Instantly share code, notes, and snippets.

@cirocosta
Last active March 5, 2020 17:14
Show Gist options
  • Save cirocosta/5c073561b1f43a2d5d560a6d8df8fa10 to your computer and use it in GitHub Desktop.
Save cirocosta/5c073561b1f43a2d5d560a6d8df8fa10 to your computer and use it in GitHub Desktop.
note

trying it out

There are two ways of trying this out:

local build

As long as you have access to a cluster, you can get Concourse to run workloads there.

However, you need to get Concourse running.

You can do so using the Makefile included in here though:

# run postgres in docker
#
make db


# start a kubernetes cluster using `kind` with a modified CRI (because ..
# containerd) that whitelists `http`-based registries.
#
make cluster


# build, install, and run Concourse (make sure you run `yarn build` 
# first to build the UI assets)
#
make run

That done, you can now access Concourse on http://localhost:8080.

using the helm chart

I've uploaded an image (cirocosta/concourse:k8s-iter-1) to DockerHub for those wanting to try out the "in-cluster" experience, and repurposed "the Helm chart of today" to support the "runtime of tomorrow".

# clone the branch of the chart where it includes the necessary RBAC configs for
# setting up a service account that's powerful enough
#
git clone \
        --branch k8s-iter-1 \
        https://github.com/concourse/concourse-chart


# clone the branch of this PR
#
git clone \
        --branch k8s-iter-1 \
        https://github.com/concourse/concourse


# get the `init` configmap into the cluster so that we can hold containers alive
# until processes are meant to be executed in them.
#
NAMESPACE=default make -C ./concourse init


# install the chart / render the templates with the sample values under
# `hack/k8s/values.yaml` from this PR's branch
#
helm dependency update ./concourse-chart
helm upgrade \
        --install \
        --values=./concourse/hack/k8s/values.yaml \
        test \
        ./concourse-chart

with the chart installed, you can now port-forward ATC (http://localhost:8080) and get going.

ps.: your cluster must have support for pulling images from http-based registries served as pods. you can have a local cluster running make -C concourse cluster if you'd like to use kind).

how it works

The execution of each step follows the same pattern as we're accustomed with when using Garden, where we set the sandbox up, and then run the desired process inside it ( db.Creating() -> container.Create() -> db.Created()... -> container.Run())

Because a build plan can be seen as a directed acyclic graph when it comes to dependencies, we can rely on that fact to dictate how each step either gathers inputs, our supplies outputs.

For each step, as long as its dependencies (including transitive ones) were able to fulfill what they should (e.g., a get successfully running /opt/resource/in), it'll be able to retrieve any artifact that it might need.

When running a step, atc communicates with Kubernetes to create pods that represent those steps.

Each step pod can be seen as a potential permutation of two configurations:

  • i. having an "inputs fetcher" init container, responsible for fetching artifacts retrieves by dependnecies
  • ii. having an "output streamer" sidecar container, responsible for providing artifacts to those who might depend on this step

For instance, task in the example above would look like:

  • having an "input fetcher" capable of retrieving data from repository and image
  • having an "output streamer" capable of streaming the artifacts it produces to the "bucket" step ("bucket" would pull from the output streamer endpoint)

so that in the end, we have this form of "peer-to-peer" communication between the pods themselves:

(arrow direction indicating "depends on")

Once done with the build, the regular internal Concourse container lifecycle would take care of moving the pods in our DB for CREATED state to DESTROYING, which the kubernetes implementation of a worker would then notice the desire to not having certain pods, and then proceed with deleting them.

concerns about the current design

The current approach presented here is very focused towards not changing much of the current constructs in our codebase as is of today.

Despite demonstrating that it is possible to run Concourse on Kubernetes, the current design might raise some eyebrows.

insecure registry whitelisting

Given that the container runtimes that kubelets communicate with need to trust the registries that they interact with, we have to rely on whitelisting the internal pod domain as trusted insecure registries.

Interestingly, this is already done by default on GKE.

next iterations

To work around this, we can explore the avenue of having the images being pushed to a central registry in the cluster that's trusted by the kubelets.

As long as we make the process of getting "input in" and "outputs out" pluggable enough, we could have either/or.

execing via apiserver

It's very convenient to be able to just exec (or attach to) a process via apiserver's exec endpoints, making the current Concourse's container lifecycle and process execution work very with pretty much no changes needed in our code flow.

It might be that this does not scale though, with apiserver being hit so hard with a system like concourse.

There can also be concerns about keeping that connection for a long time (e.g., steps that take a long time to finish their main executions), or the sheer size of throughput necessary (steps that log tons to stderr).

next iterations

If we don't want to modify the imperative nature of ATC making the requests to execute, we could have some form of "shim" that'd be mounted to every main container in step pods, which would then be reached out to by ATC, performing the task of execin processes there, and dealing with the log streams / re-attaching.

syncing handles by fetching all concourse pods

Having a pod per Concourse container will necessarily mean that we'd have a pod for each resource scope id (assuming no use of ephemeral check containers).

That means that an installation with 5000 of those would be fetching 5000 pods on every worker tick.

next iterations

This could be improved by leveraging the same mechanisms that controllers do - perhaps even making this a controller itself that gets informed on changes to pods that match the label that we have?

Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@startuml
autoactivate on
participant Concourse
participant Database
participant Kubernetes
participant CheckStep
... "sandbox" setup ...
Concourse -> Database : container CREATING
Database --> Concourse : ok
Concourse -> Kubernetes : CheckStep Pod Definition
Kubernetes --> Concourse: Ok
loop until ready or timeout
Concourse -> Kubernetes : Pod status
Kubernetes --> Concourse : Ok
end
Concourse -> Database : container CREATED
Database --> Concourse : ok
... process execution ...
Concourse -> Kubernetes : exec /opt/resource/check
Kubernetes -> CheckStep : stream
CheckStep --> Kubernetes : stream
Kubernetes --> Concourse : resource versions
@enduml
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@startuml
object repository
repository : type = "get"
object image
image : type = "get"
object task
task : type = "task"
object bucket
bucket : type = "put"
task <|-- repository
task <|-- image
bucket <|-- task
@enduml
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@startuml
title dependency graph
node "repository" {
package "repository containers" {
[repository output streamer]
[repository main container]
}
}
node "image" {
package "image containers" {
[image output streamer]
[image main container]
}
}
node "task" {
package "task init containers" {
[task input fetcher] ..> [repository output streamer]
[task input fetcher] ..> [image output streamer]
}
package "task containers" {
[task main container]
[task output streamer]
}
}
node "bucket" {
package "bucket init containers" {
[bucket input fetcher] ..> [task output streamer]
}
package "bucket containers" {
[bucket main container]
}
}
@enduml
Display the source blob
Display the rendered blob
Raw
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" contentScriptType="application/ecmascript" contentStyleType="text/css" height="454px" preserveAspectRatio="none" style="width:413px;height:454px;" version="1.1" viewBox="0 0 413 454" width="413px" zoomAndPan="magnify"><defs><filter height="300%" id="fc9g9r5aodlw9" width="300%" x="-1" y="-1"><feGaussianBlur result="blurOut" stdDeviation="2.0"/><feColorMatrix in="blurOut" result="blurOut2" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .4 0"/><feOffset dx="4.0" dy="4.0" in="blurOut2" result="blurOut3"/><feBlend in="SourceGraphic" in2="blurOut3" mode="normal"/></filter></defs><g><!--MD5=[d594f396f55cd99da73f9ec24730a411]
cluster step pod--><polygon fill="#FFFFFF" filter="url(#fc9g9r5aodlw9)" points="22,34,32,24,391,24,391,432,381,442,22,442,22,34" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="381" x2="390" y1="34" y2="25"/><line style="stroke: #000000; stroke-width: 1.5;" x1="22" x2="381" y1="34" y2="34"/><line style="stroke: #000000; stroke-width: 1.5;" x1="381" x2="381" y1="34" y2="442"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="70" x="167.5" y="49.9951">step pod</text><!--MD5=[a0822e90cc0f323f368380001996e7fe]
cluster init containers--><polygon fill="#FFFFFF" filter="url(#fc9g9r5aodlw9)" points="53,72,172,72,179,94.2969,193,94.2969,193,159,53,159,53,72" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="53" x2="179" y1="94.2969" y2="94.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="113" x="57" y="86.9951">init containers</text><!--MD5=[1ddc4b0eff0cb44bb1b0ed2e17f68b41]
cluster containers--><polygon fill="#FFFFFF" filter="url(#fc9g9r5aodlw9)" points="46,331,136,331,143,353.2969,367,353.2969,367,418,46,418,46,331" style="stroke: #000000; stroke-width: 1.5;"/><line style="stroke: #000000; stroke-width: 1.5;" x1="46" x2="143" y1="353.2969" y2="353.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="84" x="50" y="345.9951">containers</text><!--MD5=[51bd6bf392a46b13b08aa61c812e40c2]
cluster volume--><path d="M80,193 C80,183 171.5,183 171.5,183 C171.5,183 263,183 263,193 L263,297 C263,307 171.5,307 171.5,307 C171.5,307 80,307 80,297 L80,193 " fill="#FFFFFF" filter="url(#fc9g9r5aodlw9)" style="stroke: #000000; stroke-width: 1.5;"/><path d="M80,193 C80,203 171.5,203 171.5,203 C171.5,203 263,203 263,193 " fill="none" style="stroke: #000000; stroke-width: 1.5;"/><text fill="#000000" font-family="sans-serif" font-size="14" font-weight="bold" lengthAdjust="spacingAndGlyphs" textLength="57" x="143" y="217.9951">volume</text><!--MD5=[23fd9f427ef50194a47cc6d48900ce14]
entity input fetcher--><rect fill="#FEFECE" filter="url(#fc9g9r5aodlw9)" height="36.2969" style="stroke: #A80036; stroke-width: 1.5;" width="108" x="69" y="107"/><rect fill="#FEFECE" height="5" style="stroke: #A80036; stroke-width: 1.5;" width="10" x="64" y="112"/><rect fill="#FEFECE" height="5" style="stroke: #A80036; stroke-width: 1.5;" width="10" x="64" y="133.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="88" x="79" y="129.9951">input fetcher</text><!--MD5=[ab8e4350cf511f49420d1a78a1aa5523]
entity output streamer--><rect fill="#FEFECE" filter="url(#fc9g9r5aodlw9)" height="36.2969" style="stroke: #A80036; stroke-width: 1.5;" width="132" x="219" y="366"/><rect fill="#FEFECE" height="5" style="stroke: #A80036; stroke-width: 1.5;" width="10" x="214" y="371"/><rect fill="#FEFECE" height="5" style="stroke: #A80036; stroke-width: 1.5;" width="10" x="214" y="392.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="112" x="229" y="388.9951">output streamer</text><!--MD5=[adf78712d0c9e23c4bbd04e13943beb7]
entity main container--><rect fill="#FEFECE" filter="url(#fc9g9r5aodlw9)" height="36.2969" style="stroke: #A80036; stroke-width: 1.5;" width="122" x="62" y="366"/><rect fill="#FEFECE" height="5" style="stroke: #A80036; stroke-width: 1.5;" width="10" x="57" y="371"/><rect fill="#FEFECE" height="5" style="stroke: #A80036; stroke-width: 1.5;" width="10" x="57" y="392.2969"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="102" x="72" y="388.9951">main container</text><!--MD5=[fb14c9b1fd95d0c04eeb1a4af9d96e82]
entity input--><ellipse cx="123" cy="262" fill="#FEFECE" filter="url(#fc9g9r5aodlw9)" rx="8" ry="8" style="stroke: #A80036; stroke-width: 2.0;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="35" x="105.5" y="291.9951">input</text><!--MD5=[c661d977cad040094ee01910682146de]
entity output--><ellipse cx="216" cy="262" fill="#FEFECE" filter="url(#fc9g9r5aodlw9)" rx="8" ry="8" style="stroke: #A80036; stroke-width: 2.0;"/><text fill="#000000" font-family="sans-serif" font-size="14" lengthAdjust="spacingAndGlyphs" textLength="46" x="193" y="291.9951">output</text><!--MD5=[7b3937bf50aade8caf375660da148be9]
link input fetcher to input--><path d="M123,143.098 C123,170.406 123,223.285 123,247.857 " fill="none" id="input fetcher-&gt;input" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><polygon fill="#A80036" points="123,252.923,127,243.923,123,247.923,119,243.923,123,252.923" style="stroke: #A80036; stroke-width: 1.0;"/><!--MD5=[80da2c71e2cd3191e68c9b3b8e2804cb]
link output to output streamer--><path d="M220.743,271.248 C231.277,289.569 256.917,334.159 272.436,361.15 " fill="none" id="output-&gt;output streamer" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><polygon fill="#A80036" points="275.023,365.6491,274.004,355.8531,272.5305,361.3147,267.0689,359.8411,275.023,365.6491" style="stroke: #A80036; stroke-width: 1.0;"/><!--MD5=[6f2a946b596f8da84bb0af7e22c56f77]
link input to main container--><path d="M123,271.248 C123,289.417 123,333.424 123,360.4772 " fill="none" id="input-&gt;main container" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><polygon fill="#A80036" points="123,365.6491,127,356.6491,123,360.6491,119,356.6491,123,365.6491" style="stroke: #A80036; stroke-width: 1.0;"/><!--MD5=[6ec1b511e62410c31a8c910435b24933]
link main container to output--><path d="M136.447,365.6491 C155.514,341.047 189.931,296.638 206.534,275.214 " fill="none" id="main container-&gt;output" style="stroke: #A80036; stroke-width: 1.0; stroke-dasharray: 7.0,7.0;"/><polygon fill="#A80036" points="209.608,271.248,200.9328,275.9108,206.5448,275.1998,207.2558,280.8118,209.608,271.248" style="stroke: #A80036; stroke-width: 1.0;"/><!--MD5=[f433eb9f942b15ca5e5cfbe63f61409b]
@startuml
node "step pod" {
package "init containers" {
[input fetcher]
}
package "containers" {
[output streamer]
[main container]
}
database "volume" {
[input fetcher] ..> input
output ..> [output streamer]
input ..> [main container]
[main container] ..> output
}
}
@enduml
PlantUML version 1.2020.02(Sun Mar 01 10:22:07 UTC 2020)
(GPL source distribution)
Java Runtime: Java(TM) SE Runtime Environment
JVM: Java HotSpot(TM) 64-Bit Server VM
Java Version: 1.7.0_25-b15
Operating System: Linux
Default Encoding: UTF-8
Language: en
Country: US
--></g></svg>
@startuml
node "step pod" {
package "init containers" {
[input fetcher]
}
package "containers" {
[output streamer]
[main container]
}
database "volume" {
[input fetcher] ..> input
output ..> [output streamer]
input ..> [main container]
[main container] ..> output
}
}
@enduml
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@startuml
title "worker's pod reporting & gc"
control WorkerTicker
box "web node" #LightBlue
participant Worker
participant Web
end box
participant Kubernetes
participant Db
autoactivate on
...
WorkerTicker -> Worker : tick
Worker -> Kubernetes : list pods
note left
retrieve "current state"
end note
Kubernetes --> Worker : pods
Worker -> Db : update containers state
Db --> Worker: ok
Worker -> Db : find containers in DESTROYin state (desired state)
note left
retrieve "desired state"
end note
Db --> Worker: list
Worker -> Kubernetes : destroy pods from list (converge)
note left
converge
end note
Kubernetes --> Worker : ok
Worker --> WorkerTicker : Done
@enduml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment