Page MenuHomePhabricator

k8s master capacity issues
Closed, ResolvedPublic

Description

Since ~12:00 today, Kubernetes masters have been experiencing a variety of saturation issues (both network and CPU). This began around the time of adding wikikube-ctrl1001, the first of the colocated etcd/k8s control nodes in eqiad, but is probably a longer running issue that has come to a head now.

wikikube-ctrl1002 was prepped to be added to the cluster but has not been configured in confctl or uncordoned. Just for reference, codfw had 3 ctrl nodes added last week without major issue.

More context in the incident google doc.

Event Timeline

Change #1036707 had a related patch set uploaded (by CDanis; author: CDanis):

[operations/deployment-charts@master] temporarily disable otelcol @ eqiad

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

Change #1036708 had a related patch set uploaded (by CDanis; author: CDanis):

[operations/deployment-charts@master] otelcol: add three new k8s ctrl IPs

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

Change #1036707 merged by jenkins-bot:

[operations/deployment-charts@master] temporarily disable otelcol @ eqiad

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

Posting a short comment now, before I start drafting a much longer comment (and possibly don't finish before my toddler ends my day):

I believe the situation to be stable for now.
I am becoming convinced we've been close to this saturation point during Mediawiki releases specifically for weeks.
I am also becoming convinced that adding the new control plane metal nodes turned this from a CPU saturation issue into a NIC saturation issue, and the latter causes probes to fail much harder than CPU saturation.

tldr:

  • Adding the new control plane workers in eqiad turned what was a CPU saturation issue (causing blackbox probes to be slow but still within timeouts), into a simultaneous CPU and NIC saturation issue (causing probes to exceed their timeout, fail, and then page oncall)
  • We should absolutely continue and finish the wikikube-ctrl work, but preferably not overlapping with a MW deploy.
  • We should turn otelcol back on; turning it back on will go much better than having it on while we perform this work did.
This was a capacity crunch triggered by expensive operations (i.e. Mediawiki deploys)
  • For the past few months, during any MW deploy, we've been saturating k8s control plane CPU in both eqiad and codfw
    • Above queries have some arcane PromQL incantations to make the brief spikes more visible at this long time range. But it is not a distortion: the durations of the spikes are being increased to show more readily on a long time duration plot, but the amplitudes are slightly reduced -- so if anything, this under-plays the saturation issue. And it still looks not great.
  • We also see slowly-increasing blackbox probe duration against API servers in both clusters: https://grafana.wikimedia.org/goto/hIvtEZsSg?orgId=1
  • A few times we triggered a rolling restart of mw-api-int pods in eqiad to deliberately cause the CPU/network TX spikes on the two original masters, so we could observe more about the behavior. We wanted to figure out "what had changed" such that a scap deploy was now creating a ProbeDown page.
    • We captured pcaps on a few different k8s masters during such events, and then ran that through wireshark's Statistics > Conversations feature. Here's one such breakdown. I sorted the list of streams by bytes and manually tagged the top dozen or so streams. I stopped a few entries into a very long run of nearly-identical byte counts from local port 6443 (apiserver) to different node IPs; if you sum up the ones I tagged plus all of those, that makes up 97% of the bytes in the sample.
    • Of that 97% portion I inspected, everything sending packets to and from the apiserver machines was reasonable-looking: reading from an etcd's port 2380 was about 5% of overall bytes, then after that, in order, the apiserver sending lots of data to all of: the istiod pod, a calico-kube-controllers pod, a k8s-controller-sidecars pod, various different node IPs (so one of kubelet, kube-proxy, or rsyslogd)... all of them expected, known usages of the API.
    • This is 'just' absence of evidence but I'm gonna go ahead and call it evidence of absence here.
  • Even after otelcol was disabled, during rollouts we were able to create some CPU saturation
    • And during later rollouts, we were sending pretty significant bps from the new wikikube-ctrl1* servers as well. It was still impossible for otelcol to contact those servers at that time.
Red herrings along the way:
  • etcdctl cluster-health was broken by aggressive firewalling in our current setup, and we didn't know this was true until we tried to use it as a debugging tool mid-incident
  • The excessive TCP retransmits that got my attention were really a byproduct of the NIC being way too hot on tx, which at this point I think is because we accidentally steered a large WATCH user -- otelcol -- towards the two on-ganeti masters, because we hadn't allowed it to talk to any of the new nodes.
Things we learned today:
  • Adjusting the conftool weight on a kubemaster ... probably doesn't do all that much? A lot of things that want to talk to the kubemaster aren't doing so via LVS, but are running inside a pod and calling InClusterConfig in the golang client, or whatever.
  • Cordoning a new control plane node stops 'user' pods from running on it, but doesn't stop it from running an apiserver, nor does it stop it from appearing in the k8s API as a valid Endpoint for the cluster (e.g. kubectl get endpoints kubernetes -n default -oyaml). So I think they're getting traffic potentially as soon as apiserver is running and healthy?
Rampant speculation and conjecture
  • My best guess is that we won't always want to couple etcd with the kube-apiserver. kube-apiserver is the horizontally-scalable part of a lot of How K8s Works. Please allow me to be slightly ridiculous for a moment. It is educationally useful to imagine kube-apiserver as "a CDN* for etcd" [*: with at least as much business logic as ours]. Or perhaps better, to imagine kube-apiserver as Mediawiki, and etcd as MariaDB.
  • We've seen backend load imbalance issues on LVS services before due to very-long-lived connections which got reused indefinitely. I think there are likely similar issues in how kube-proxy works, and specifically in how kube-apiserver and k8s WATCH clients interact. Probably worth our time to see if either of kube-apiserver or k8s.io/client-go have worried about this issue.

Icinga downtime and Alertmanager silence (ID=b65d2df8-871b-4064-b329-026af4d7ec1d) set by akosiaris@cumin1002 for 2:00:00 on 1 host(s) and their services with reason: disable puppet and k8s controlplane

wikikube-ctrl1001.eqiad.wmnet

Icinga downtime and Alertmanager silence (ID=8fa8366a-d3f2-4a77-8e2b-45de66551026) set by akosiaris@cumin1002 for 2:00:00 on 1 host(s) and their services with reason: disable puppet and k8s controlplane

wikikube-ctrl1002.eqiad.wmnet

Icinga downtime and Alertmanager silence (ID=2f1b90d9-2cd4-4705-bbf1-70fdacf169cd) set by akosiaris@cumin1002 for 2:00:00 on 1 host(s) and their services with reason: disable puppet and k8s controlplane

kubemaster1002.eqiad.wmnet

Mentioned in SAL (#wikimedia-operations) [2024-05-29T11:04:12Z] <akosiaris> redeploy opentelemetry collector T366094

Mentioned in SAL (#wikimedia-sre) [2024-05-29T11:23:04Z] <akosiaris> T366094 re-undeploy otel-collector, it being around increased traffic to the API >50%

Mentioned in SAL (#wikimedia-sre) [2024-05-29T11:23:04Z] <akosiaris> T366094 re-undeploy otel-collector, it being around increased traffic to the API >50%

FWIW I think this traffic increase will not be an issue once we move to the new three control plane nodes

Change #1037083 had a related patch set uploaded (by CDanis; author: CDanis):

[operations/deployment-charts@master] otelcol: disable logs & metrics pipelines

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

I 've gone ahead and created the following dashboard today T366094

Intro

I have annotated (timings are roughly placed, but shouldn't matter) my tests with descriptions about what the setup was in each test, so make sure to have the annotations enabled but here is a rundown here for completeness. The tests are progressing in a linear manner, in bold the difference from the previous test. Note that while I give some ratios, those are from the side of scap, not accounting for number of pods. Note that I avoided restarting mw-jobrunners and mw-misc as I didn't see a point in either.

Tests

  1. No opentelemetry collector. kubemaster100{1,2} in full service. wikikube-ctrl1001 in partial service, it wasn't enabled in pybal, wikikube-ctrl1002 partially enabled, wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 1/8 of scap deployments, using mw-api-int
  2. No opentelemetry collector. kubemaster100{1,2} in full service. wikikube-ctrl1001 in partial service, it wasn't enabled in pybal, wikikube-ctrl1002 partially enabled, wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 1/4 of scap deployments, using mw-api-int, mw-parsoid
  3. No opentelemetry collector. kubemaster100{1,2} in full service. wikikube-ctrl100{1,2} fully depooled, control-plane on them disabled. wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 1/4 of scap deployments, using mw-api-int, mw-parsoid
  4. No opentelemetry collector. kubemaster1001 in full service. kubemaster1002 with control plane disabled. wikikube-ctrl100{1,2} fully depooled, control-plane on them disabled**. wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 1/4 of scap deployments, using mw-api-int, mw-parsoid
  5. No opentelemetry collector. kubemaster1001 in full service. kubemaster1002 with control plane disabled. wikikube-ctrl100{1,2} fully depooled, control-plane on them disabled. wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 1/2 of scap deployments, using mw-api-int, mw-parsoid, mw-wikifunctions, mw-debug
  6. No opentelemetry collector. kubemaster1001 in full service. kubemaster1002 with control plane disabled. wikikube-ctrl100{1,2} fully depooled, control-plane on them disabled. wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 1/2 of scap deployments, using mw-api-int, mw-parsoid, mw-wikifunctions, mw-debug. Pybal fix and restart for depool threshold to avoid connection errors as it refused to depool kubemaster1002
  7. No opentelemetry collector. kubemaster1001 in full service. kubemaster1002 with control plane disabled. wikikube-ctrl100{1,2} fully depooled, control-plane on them disabled. wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 3/4 (this is as far as I was willing to) of scap deployments, using mw-api-int, mw-parsoid, mw-wikifunctions, mw-debug, mw-web, mw-api-ext Pybal fix and restart for depool threshold to avoid connection errors as it refused to depool kubemaster1002
  8. Enabled opentelemetry collector. kubemaster1001 in full service. kubemaster1002 with control plane disabled. wikikube-ctrl100{1,2} fully depooled, control-plane on them disabled. wikikube-ctrl1003 only having etcd around. No opentelemetry collector running. Simulating 3/4 of scap deployments, using mw-api-int, mw-parsoid, mw-wikifunctions, mw-debug, mw-web, mw-api-ext. Pybal fix and restart for depool threshold to avoid connection errors as it refused to depool kubemaster1002

Summary of findings

  • We never had any serious form of NIC saturation. In 1 occasion we did see a number of TCP retransmits (~300segments/s). That was before restarting pybal with a lower depool_threshold to force it to eject kubemaster1002.
  • The newer wikikube-ctrl hosts definitely help in reducing CPU saturation on the older kubemaster100{1,2} hosts. I was able to trigger substantial CPU saturation once the number of deployments went up. However, I could reproduce > 60% of CPU saturation on the older hosts even with 1 deployments.
  • Network traffic wasn't correlated to the CPU in any tests. In fact, despite CPU saturation increasing network traffic stayed at a constant peak of ~90MB/s though all but the last test.
  • We never were memory bound.
  • When we disabled the control-plane on wikikube-ctrl100{1,2} we saw just 5MB/s of traffic reaching them. This matches up @CDanis's findings in T366094#9840665 of etcd traffic being ~5MB/s. Those 5MB/s see to create spikes of 16-25MB/s of disk write IO.
  • Enabling the otelcollector increased NIC usage by >50% (from ~90MB/s to 155MB/s). It also increased the duration of the 100% CPU saturation event.

Miscellanea

One more thing we verified before the tests. The new servers have 1Gbps NICs.

sudo cumin 'wikikube-ctrl*' 'ethtool eno1|grep Speed'
6 hosts will be targeted:
wikikube-ctrl[2001-2003].codfw.wmnet,wikikube-ctrl[1001-1003].eqiad.wmnet
<snip>                         
        Speed: 1000Mb/s

Thanks for writing down all of this.

===== This was a capacity crunch triggered by expensive operations

  • For the past few months, during any MW deploy, we've been saturating k8s control plane CPU in both eqiad and codfw
    • Above queries have some arcane PromQL incantations to make the brief spikes more visible at this long time range. But it is not a distortion: the durations of the spikes are being increased to show more readily on a long time duration plot, but the amplitudes are slightly reduced -- so if anything, this under-plays the saturation issue. And it still looks not great.
  • We also see slowly-increasing blackbox probe duration against API servers in both clusters: https://grafana.wikimedia.org/goto/hIvtEZsSg?orgId=1

Agreed. Thanks for those graphs, they are pretty telling.

reading from an etcd's port 2380 was about 5% of overall bytes

This matches the tests I ran today, which is encouraging.

  • Even after otelcol was disabled, during rollouts we were able to create some CPU saturation

And reproduced again today. Even with double the amount of CPUs for masters, we still had the issue. The new wikikube-ctrl nodes should help a lot to fix this.

Things we learned today:
  • Adjusting the conftool weight on a kubemaster ... probably doesn't do all that much? A lot of things that want to talk to the kubemaster aren't doing so via LVS, but are running inside a pod and calling InClusterConfig in the golang client, or whatever.

Things inside pods are indeed relying on Kubernetes Service implementations which just DNATs to the IPs of the servers. Things outside the cluster talk to the apiserver via LVS. Anything that does a WATCH, is using a websocket and isn't going to restart the ongoing connection. This matches up this observation.

  • Cordoning a new control plane node stops 'user' pods from running on it, but doesn't stop it from running an apiserver, nor does it stop it from appearing in the k8s API as a valid Endpoint for the cluster (e.g. kubectl get endpoints kubernetes -n default -oyaml). So I think they're getting traffic potentially as soon as apiserver is running and healthy?

Only for workloads inside the cluster, but otherwise yes.

Rampant speculation and conjecture
  • My best guess is that we won't always want to couple etcd with the kube-apiserver. kube-apiserver is the horizontally-scalable part of a lot of How K8s Works. Please allow me to be slightly ridiculous for a moment. It is educationally useful to imagine kube-apiserver as "a CDN* for etcd" [*: with at least as much business logic as ours]. Or perhaps

better, to imagine kube-apiserver as Mediawiki, and etcd as MariaDB.

It doesn't sounds very ridiculous for what it's worth. When we setup those clusters, we didn't collocate for this exact reason.

  • We've seen backend load imbalance issues on LVS services before due to very-long-lived connections which got reused indefinitely. I think there are likely similar issues in how kube-proxy works, and specifically in how kube-apiserver and k8s WATCH clients interact. Probably worth our time to see if either of kube-apiserver or k8s.io/client-go have worried about this issue.

As pointed out above, WATCHes are websockets. Not much you can do for load balancing such persistent connections. Not everything is a WATCH though, so the rest of the load balancing still applies.

Mentioned in SAL (#wikimedia-sre) [2024-05-29T11:23:04Z] <akosiaris> T366094 re-undeploy otel-collector, it being around increased traffic to the API >50%

FWIW I think this traffic increase will not be an issue once we move to the new three control plane nodes

I am gonna disagree on this one. This says that outgoing traffic from kubemasters can each 272MB/s, which is ~2.1Gbps, which is > 2/3 of the total NIC capacity of the 3 new control plane nodes.

Change #1036708 merged by jenkins-bot:

[operations/deployment-charts@master] otelcol: add three new k8s ctrl IPs

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

Change #1037083 merged by jenkins-bot:

[operations/deployment-charts@master] otelcol: disable logs & metrics pipelines

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

Change #1037113 had a related patch set uploaded (by CDanis; author: CDanis):

[operations/deployment-charts@master] otelcol: limit collected k8s data

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

Change #1037113 merged by jenkins-bot:

[operations/deployment-charts@master] otelcol: limit collected k8s data

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

I am gonna disagree on this one. This says that outgoing traffic from kubemasters can each 272MB/s, which is ~2.1Gbps, which is > 2/3 of the total NIC capacity of the 3 new control plane nodes.

Yes, you were right about this.

I spent most of my day looking at ways to reduce otelcol's hunger for bytes.

https://grafana.wikimedia.org/d/d304d897-54ea-4062-a504-6f2567ed7dba/t366094?orgId=1&from=1716971493322&to=1717017967022

We're still running otelcol in codfw, with the k8sattributesprocessor, so I pushed some changes there and mostly used the usual daily scap backports to generate load as I changed things. One of the nice things about that is it also provides eqiad (with otelcol still disabled) as a free control.

  • At about 14:30 I deployed https://gerrit.wikimedia.org/r/c/1037083 which did greatly affect kube-apiserver's reported WATCH rps. Judging from some more PromQL spaghetti I put together (see panel #3), I think that this cut the total number of network bytes transmitted during rollouts by about 20%.
  • At about 20:00 I deployed https://gerrit.wikimedia.org/r/c/1037113 which brought the rate of WATCH on replicasets to near-0, and seemed to reduce total network bytes by about another 10%.

I think that query is a reasonable proxy for total bytes "needed" to complete a rollout, assuming the configuration/provisioning of the apiservers stays the same between runs (since the configuration changes overheads). In the panel above it there's also a "total peak Gbps" metric, but the smoothed one is a lot easier to compare over time if you're zoomed out far.

In my morning let's try to chat about next steps? With these improvements I'm feeling decent about trying to turn otelcol back on in eqiad. If that needed to be conditional on leaving the kubemaster1xxx/2xxx machines around until we fix T366205+T366204, I'd be happy to help with any work needed for that.

I am gonna disagree on this one. This says that outgoing traffic from kubemasters can each 272MB/s, which is ~2.1Gbps, which is > 2/3 of the total NIC capacity of the 3 new control plane nodes.

Yes, you were right about this.

I spent most of my day looking at ways to reduce otelcol's hunger for bytes.

https://grafana.wikimedia.org/d/d304d897-54ea-4062-a504-6f2567ed7dba/t366094?orgId=1&from=1716971493322&to=1717017967022

We're still running otelcol in codfw, with the k8sattributesprocessor, so I pushed some changes there and mostly used the usual daily scap backports to generate load as I changed things. One of the nice things about that is it also provides eqiad (with otelcol still disabled) as a free control.

  • At about 14:30 I deployed https://gerrit.wikimedia.org/r/c/1037083 which did greatly affect kube-apiserver's reported WATCH rps. Judging from some more PromQL spaghetti I put together (see panel #3), I think that this cut the total number of network bytes transmitted during rollouts by about 20%.
  • At about 20:00 I deployed https://gerrit.wikimedia.org/r/c/1037113 which brought the rate of WATCH on replicasets to near-0, and seemed to reduce total network bytes by about another 10%.

I think that query is a reasonable proxy for total bytes "needed" to complete a rollout, assuming the configuration/provisioning of the apiservers stays the same between runs (since the configuration changes overheads). In the panel above it there's also a "total peak Gbps" metric, but the smoothed one is a lot easier to compare over time if you're zoomed out far.

In my morning let's try to chat about next steps? With these improvements I'm feeling decent about trying to turn otelcol back on in eqiad. If that needed to be conditional on leaving the kubemaster1xxx/2xxx machines around until we fix T366205+T366204, I'd be happy to help with any work needed for that.

@akosiaris given that now we have 5 kubernetes masters in each DC, any objections in having another go at otel?

Change #1037548 had a related patch set uploaded (by CDanis; author: CDanis):

[operations/deployment-charts@master] re-enable otelcol in eqiad

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

Change #1037548 merged by jenkins-bot:

[operations/deployment-charts@master] re-enable otelcol in eqiad

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

https://grafana.wikimedia.org/goto/1rSRUSsSg?orgId=1

{F54904024}

As we expected/hoped, the increase in eqiad TX bytes was only about 10-15%.

CDanis claimed this task.

Boldly closing this because we've resolved all of T353464: Migrate wikikube control planes to hardware nodes and the two tasks for 10G NICs T366204 T366205