Page MenuHomePhabricator

Make scap deploy to kubernetes together with the legacy systems
Closed, ResolvedPublic8 Estimated Story Points

Description

As part of our move to kubernetes, we need to be able, at least for the transition period, to deploy mediawiki to kubernetes at the same time we deploy it to the main cluster. This means that scap sync (and its various variations) should deploy also to kubernetes for the time being.

Deployment workflow

1 - code is prepared in /srv/mediawiki-staging by a scap command, that also builds the corresponding docker images, and publishes them to the docker registry. This procedure also commits a series of yaml files to the git repository at /etc/helmfile-defaults/mediawiki/release. Sync-masters in scap should probably also sync this repository. These yaml files will all have the following format:

main_app: 
  image: 'restricted/mediawiki-multiversion:<tag>'
mw:
  httpd: 
    image_tag: 'restricted/mediawiki-webserver:<tag>'

The various files might include different flavors of the mediawiki-multiversion image, based on configuration (see below). The file names will be in the form <namespace>-<release>.yaml, see below on how they can be extracted.
2 - Instead of suggesting to scap pull on one debug server, we should have a "scap sync-debug" stage that does deploy just to the debug servers and the debug namespaces on kubernetes (again coming from configuration).
3 - scap sync* would work like now, with the difference that:

  • while deploying to the canaries, we should also deploy to the combination of clusters, namespaces indicated in a configuration key (see below) to the release canary.
  • canary checks will need to use a better logstash query than the one used today. I think introducing a more fine-grained set of servergroups variables will help here.
  • When deploying to all appservers, we would need to deploy to to the same cluster/namespaces, but to release main

4 - A rollback can be achieved by reverting the last change in the repository described above, or using the traditional process described above.

Configuration
We will need a series of configuration keys:

  • k8s_releases_dir - the directory where the releases repository is located.
  • k8s_clusters - the list of clusters to deploy to.
  • k8s_deployments_file - a file path for a yaml file containing the data structure described below.

This file will contain a list of dictionaries dictionary built as follows:

---
- namespace: mwdebug
  release: pinkunicorn
  canary:
  mw_flavour: debug
  web_flavour: production
  debug: true
- namespace: parsoid
  release: parsoid
  canary: parsoid-canary
  mw_flavour: production
  web_flavour: production
...

where:

  • namespace is the k8s namespace
  • release is the helmfile release name
  • mw_flavour to indicate if we want the "main" image (-publish, hopefully changing to production soon) or the "debug" image (-debug), or any other flavour we might be building in the release file for this namespace.
  • web_flavour same thing, but for the webserver image.
  • debug (boolean) if this is a debug namespace or not
  • canary (optional) is the name of the canary helmfile release

as for "how to release to k8s", the best way to achieve it is probably running helmfile -e <cluster> -l <release> sync using /srv/deployment-charts/helmfile.d/services/<namespace> as the current working directory. Some relevant code can be found in the current autodeployment script

Details

Related Changes in Gerrit:
SubjectAuthorRepoBranchLines +/-
Jaime Nuchemediawiki/tools/scapmaster+7 -1
Jaime Nuchemediawiki/tools/scapmaster+426 -170
Jaime Nucheoperations/puppetproduction+9 -8
Ahmon Dancymediawiki/tools/scapmaster+102 -65
Ahmon Dancymediawiki/tools/train-devmaster+16 -101
Ahmon Dancyoperations/puppetproduction+8 -7
Ahmon Dancyoperations/puppetproduction+1 -0
Ahmon Dancyoperations/deployment-chartsmaster+59 -2
Ahmon Dancymediawiki/tools/releasemaster+4 -0
Ahmon Dancyoperations/puppetproduction+14 -3
Ahmon Dancyoperations/deployment-chartsmaster+1 -1
Ahmon Dancymediawiki/tools/releasemaster+4 -0
Giuseppe Lavagettooperations/puppetproduction+22 -13
Giuseppe Lavagettooperations/puppetproduction+8 -2
Jcrespooperations/puppetproduction+1 -1
Giuseppe Lavagettooperations/puppetproduction+72 -0
Show related patches Customize query in gerrit

Event Timeline

Change 767756 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] deployment_server: add mediawiki on k8s releases repo

https://gerrit.wikimedia.org/r/767756

Change 767756 merged by Giuseppe Lavagetto:

[operations/puppet@production] deployment_server: add mediawiki on k8s releases repo

https://gerrit.wikimedia.org/r/767756

Change 773559 had a related patch set uploaded (by Jcrespo; author: Jcrespo):

[operations/puppet@production] bacula: Unbreak director: disable deployment backups

https://gerrit.wikimedia.org/r/773559

Change 773581 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] backup: fix filesets definition for mw on k8s

https://gerrit.wikimedia.org/r/773581

Change 773559 abandoned by Jcrespo:

[operations/puppet@production] bacula: Unbreak director: disable deployment backups

Reason:

proper fix: https://gerrit.wikimedia.org/r/c/operations/puppet/+/773581

https://gerrit.wikimedia.org/r/773559

Change 773581 merged by Giuseppe Lavagetto:

[operations/puppet@production] backup: fix filesets definition for mw on k8s

https://gerrit.wikimedia.org/r/773581

Proposal for preparing for a transitiom from the current autodeployment script:

  1. Make deploy-mwdebug.py run as mwbuilder instead of root. This means that /var/lib/deploy-mwdebug and files therein will need to be chowned to mwbuilder. This also means that mwbuilder must be allowed to run helmfile apply (which mostly means that it needs to be able to read relevant values files).
  2. Change VALUES_FILE in deploy-mwdebug.py to point to a file in /etc/helmfile-defaults/mediawiki/releases/
  3. Change operations/deployment-charts/helmfile.d/services/mwdebug/helmfile.yaml to point to the yaml file in /etc/helmfile-defaults/mediawiki/releases/ instead of /etc/helmfile-defaults/mediawiki/releases.yaml

I'd like to be able to work alongside the deploy-mwdebug.py until the transition is finalized, so I need a way to pause and unpause it, ideally by creating and deleting a file.

@Joe What do you think?

Change 778285 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] mwdebug-deploy: run as mwbuilder, use release repository

https://gerrit.wikimedia.org/r/778285

Joe claimed this task.
This comment was removed by Joe.
Joe removed Joe as the assignee of this task.

sorry for the mistake, I commented on the wrong task.

Change 778285 merged by Giuseppe Lavagetto:

[operations/puppet@production] mwdebug-deploy: run as mwbuilder, use release repository

https://gerrit.wikimedia.org/r/778285

Proposal for preparing for a transitiom from the current autodeployment script:

  1. Make deploy-mwdebug.py run as mwbuilder instead of root. This means that /var/lib/deploy-mwdebug and files therein will need to be chowned to mwbuilder. This also means that mwbuilder must be allowed to run helmfile apply (which mostly means that it needs to be able to read relevant values files).
  2. Change VALUES_FILE in deploy-mwdebug.py to point to a file in /etc/helmfile-defaults/mediawiki/releases/
  3. Change operations/deployment-charts/helmfile.d/services/mwdebug/helmfile.yaml to point to the yaml file in /etc/helmfile-defaults/mediawiki/releases/ instead of /etc/helmfile-defaults/mediawiki/releases.yaml

I'd like to be able to work alongside the deploy-mwdebug.py until the transition is finalized, so I need a way to pause and unpause it, ideally by creating and deleting a file.

@Joe What do you think?

I agree, in fact I've just implemented these changes. We'll see if something fails next time we try to run the deployment.

Change 778535 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[mediawiki/tools/release@master] Add clear-deploy-mwdebug-error Makefile target

https://gerrit.wikimedia.org/r/778535

Change 778535 merged by jenkins-bot:

[mediawiki/tools/release@master] Add clear-deploy-mwdebug-error Makefile target

https://gerrit.wikimedia.org/r/778535

Change 787054 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[operations/deployment-charts@master] Update path to values file with image names

https://gerrit.wikimedia.org/r/787054

Change 787054 merged by jenkins-bot:

[operations/deployment-charts@master] Update path to values file with image names

https://gerrit.wikimedia.org/r/787054

Change 787108 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[operations/puppet@production] Allow deploy-mwdebug.py to be paused externally

https://gerrit.wikimedia.org/r/787108

Change 787108 merged by RLazarus:

[operations/puppet@production] Allow deploy-mwdebug.py to be paused externally

https://gerrit.wikimedia.org/r/787108

Change 787529 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[mediawiki/tools/release@master] make-container-image: Add Makefile target to pause/unpause deploy-mwdebug

https://gerrit.wikimedia.org/r/787529

Change 787529 merged by jenkins-bot:

[mediawiki/tools/release@master] make-container-image: Add Makefile target to pause/unpause deploy-mwdebug

https://gerrit.wikimedia.org/r/787529

@Joe Regarding https://gerrit.wikimedia.org/g/operations/puppet/+/refs/changes/56/767756/7/hieradata/role/common/deployment_server/kubernetes.yaml#233 :

Is the idea that profile::kubernetes::deployment_server::mediawiki::release::mw_releases will eventually list all the desired stages (e.g, mwdebug, canaries, production)? If so, can we change the value to a list of objects?

Change 789659 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[mediawiki/tools/scap@master] WIP: Deploy mw image to clusters defined in config

https://gerrit.wikimedia.org/r/789659

Change 789669 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[mediawiki/tools/train-dev@master] WIP mw container deployment stuff

https://gerrit.wikimedia.org/r/789669

Change 800758 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[operations/puppet@production] Turn mw_releases into a list

https://gerrit.wikimedia.org/r/800758

@Joe Regarding https://gerrit.wikimedia.org/g/operations/puppet/+/refs/changes/56/767756/7/hieradata/role/common/deployment_server/kubernetes.yaml#233 :

Is the idea that profile::kubernetes::deployment_server::mediawiki::release::mw_releases will eventually list all the desired stages (e.g, mwdebug, canaries, production)? If so, can we change the value to a list of objects?

@Joe I prepared https://gerrit.wikimedia.org/r/800758. Awaiting your approval.

Change 798883 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[operations/deployment-charts@master] mwdebug service: Add traindev environment support

https://gerrit.wikimedia.org/r/798883

Change 802795 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[operations/puppet@production] scap.cfg.erb: Set release_repo_update_mediawiki_releases_values_cmd

https://gerrit.wikimedia.org/r/802795

Change 798883 merged by jenkins-bot:

[operations/deployment-charts@master] mwdebug service: Add traindev environment support

https://gerrit.wikimedia.org/r/798883

Change 802795 merged by Alexandros Kosiaris:

[operations/puppet@production] scap.cfg.erb: Set release_repo_update_mediawiki_releases_values_cmd

https://gerrit.wikimedia.org/r/802795

Change 800758 merged by Giuseppe Lavagetto:

[operations/puppet@production] Turn mw_releases into a list

https://gerrit.wikimedia.org/r/800758

Change 789669 merged by jenkins-bot:

[mediawiki/tools/train-dev@master] Initial mw container deployment stuff

https://gerrit.wikimedia.org/r/789669

Change 789659 merged by jenkins-bot:

[mediawiki/tools/scap@master] k8s: deploy to debug namepsace during testservers deployment

https://gerrit.wikimedia.org/r/789659

Mentioned in SAL (#wikimedia-operations) [2022-09-02T18:40:02Z] <dancy@deploy1002> Started scap: testing T299648

Mentioned in SAL (#wikimedia-operations) [2022-09-02T18:56:07Z] <dancy@deploy1002> dancy: testing T299648 synced to the testservers: mwdebug2001.codfw.wmnet, mwdebug1002.eqiad.wmnet, mwdebug2002.codfw.wmnet, mwdebug1001.eqiad.wmnet

I ran this successfully today:

~dancy/devel-scap sync-world -Dbuild_mw_container_image:True -Ddeploy_mw_container_image:True --pause-after-testserver-sync testing T299648

@Joe we were thinking we can flatten the configs one level, since we are already parsing the entries as a list. Your example above would look like:

- namespace: mwdebug 
  release: main
  canary:
  mw_flavour: publish
  web_flavour: webserver
  debug: false

This would only require a small change on the Puppet config, we could create the patches ourselves.

Change 830675 had a related patch set uploaded (by Jaime Nuche; author: Jaime Nuche):

[mediawiki/tools/scap@master] K8s: add parsing of deployments configuration file

https://gerrit.wikimedia.org/r/830675

Change 830850 had a related patch set uploaded (by Jaime Nuche; author: Jaime Nuche):

[operations/puppet@production] k8s scap: change format of mediawiki deployment files

https://gerrit.wikimedia.org/r/830850

Change 830864 had a related patch set uploaded (by Jaime Nuche; author: Jaime Nuche):

[mediawiki/tools/scap@master] k8s: reset local logs between runs

https://gerrit.wikimedia.org/r/830864

Change 830850 merged by Jbond:

[operations/puppet@production] k8s scap: change format of mediawiki deployment files

https://gerrit.wikimedia.org/r/830850

Change 830675 merged by jenkins-bot:

[mediawiki/tools/scap@master] K8s: add parsing of deployments configuration file

https://gerrit.wikimedia.org/r/830675

Change 830864 merged by jenkins-bot:

[mediawiki/tools/scap@master] k8s: reset local logs between runs

https://gerrit.wikimedia.org/r/830864

Mentioned in SAL (#wikimedia-operations) [2022-09-13T21:04:32Z] <dancy@deploy1002> Started scap: testing T299648

Mentioned in SAL (#wikimedia-operations) [2022-09-13T21:15:10Z] <dancy@deploy1002> dancy: testing T299648 synced to the testservers: mwdebug1002.eqiad.wmnet, mwdebug2002.codfw.wmnet, mwdebug2001.codfw.wmnet, mwdebug1001.eqiad.wmnet

@Joe (and others) Is there any objection to scap running helmfile apply for both eqiad and codfw in parallel? Right now they are serialized and it feels inefficient.

Notes on the impact on deployer experience when scap config flags build_mw_container_image and deploy_mw_container_image are enabled on the deploy server. I tested this by running
scap sync-world -Dbuild_mw_container_image:True -Ddeploy_mw_container_image:True --pause-after-testserver-sync testing many times back-to-back.

build-and-push-container-images timings
21:10:16 Finished build-and-push-container-images (duration: 05m 40s)
21:37:11 Finished build-and-push-container-images (duration: 00m 17s)
21:48:00 Finished build-and-push-container-images (duration: 00m 20s)
21:55:41 Finished build-and-push-container-images (duration: 00m 21s)
22:02:59 Finished build-and-push-container-images (duration: 00m 20s)
22:08:10 Finished build-and-push-container-images (duration: 00m 20s)
22:13:08 Finished build-and-push-container-images (duration: 00m 20s)

The time to build and push container images is steady after build_mw_container_image is first enabled (when it has to build a big initial image). Let's call it 20 seconds of added time after the initial cost. Not too bad.

container-deployment timings
21:14:33 Finished Running helmfile -e eqiad apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 04m 00s)
21:14:55 Finished Running helmfile -e codfw apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 00m 04s)

21:50:38 Finished Running helmfile -e eqiad apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 02m 20s)
21:54:47 Finished Running helmfile -e codfw apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 03m 54s)

21:58:40 Finished Running helmfile -e eqiad apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 02m 42s)
22:01:17 Finished Running helmfile -e codfw apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 02m 21s)

22:05:59 Finished Running helmfile -e eqiad apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 02m 44s)
22:06:46 Finished Running helmfile -e codfw apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 00m 39s)

22:10:50 Finished Running helmfile -e eqiad apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 02m 24s)
22:11:51 Finished Running helmfile -e codfw apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 00m 45s)

22:14:05 Finished Running helmfile -e eqiad apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 00m 40s)
22:14:54 Finished Running helmfile -e codfw apply in /srv/deployment-charts/helmfile.d/services/mwdebug (duration: 00m 42s)

It takes a long time for the deployment time to settle. This is because new pods can be scheduled to a variety of possible nodes and a selected node may not have the large initial image pulled, delaying the deployment. In the best case (when new pods are scheduled to nodes that already have the initial layers), about 80 seconds of time is added to a scap sync-world deployment. This can be halved to ~40 seconds by deploying to each DC in parallel.

@Joe (and others) Is there any objection to scap running helmfile apply for both eqiad and codfw in parallel? Right now they are serialized and it feels inefficient.

@Joe responded via IRC saying that he had no objection to this so I'll start work on it.

Change 832338 had a related patch set uploaded (by Ahmon Dancy; author: Ahmon Dancy):

[mediawiki/tools/scap@master] Perform k8s deployments in parallel

https://gerrit.wikimedia.org/r/832338

Scap is already generating Helmfile configuration files as described here and using them to deploy to K8s. Created T318536 to keep track of remaining work.