Skip to content

feat(arena): introduction to kubernetes notebook#68

Open
rawkode wants to merge 4 commits into
mainfrom
arena/k8s
Open

feat(arena): introduction to kubernetes notebook#68
rawkode wants to merge 4 commits into
mainfrom
arena/k8s

Conversation

@rawkode

@rawkode rawkode commented Apr 8, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@rawkode rawkode marked this pull request as ready for review May 13, 2026 14:39
Copilot AI review requested due to automatic review settings May 13, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new marimo notebook that walks ARENA users through Kubernetes basics (namespace, ConfigMap, Deployment, Service, Job, cleanup) by applying real manifests against a CKS cluster, either via in-cluster service-account credentials or a local kubectl context.

Changes:

  • New arena/notebooks/cks_kubernetes.py notebook with helper functions for shelling out to kubectl, applying YAML manifests via stdin, and rendering imperative/declarative step cells with Run buttons.
  • In-cluster kubeconfig generation from the mounted service-account token, written to /tmp/arena-incluster-kubectl.yaml and exported via KUBECONFIG.
  • Lab content covering ConfigMap CRUD, Deployment scaling/self-healing/rolling update, Service + Endpoints, Job to completion, and namespace cleanup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread arena/notebooks/cks_kubernetes.py Outdated
Comment thread arena/notebooks/cks_kubernetes.py Outdated
Comment thread arena/notebooks/cks_kubernetes.py Outdated
Comment thread arena/notebooks/cks_kubernetes.py Outdated
@rawkode rawkode force-pushed the arena/k8s branch 2 times, most recently from c09ff02 to 0453cfb Compare May 13, 2026 14:46
Comment thread arena/notebooks/cks_kubernetes.py Outdated
Comment thread arena/notebooks/cks_kubernetes.py Outdated
Comment thread arena/notebooks/cks_kubernetes.py Outdated
Comment thread arena/notebooks/cks_kubernetes.py Outdated
@rawkode

rawkode commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

@MYanello Ready for another look, I've been through it a dozen times now and I think I've hit anything I can refactor to.

No rush, we can pick this up another day.

Comment on lines +239 to +240
"""Treat failed commands as false while preserving string truthiness for stdout."""
return self.ok and len(self) > 0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. What happens for a failed command that produces non empty stdout?

current-context: in-cluster
"""
with open(kubeconfig_path, "w", encoding="utf-8") as file:
file.write(kubeconfig)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: make this file 600 perms

"2. List Namespaces",
"kubectl get namespace",
env_b2,
env_b2.value > 0,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of these >0 buttons will stay permanently true so reclicking won't work. this may be no big deal, but worth mentioning

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also means that on any rerun to the cell (due to cm_editor changing I think), it will re-click all the buttons since .value will always be >0 after first click. Maybe inconsequential but should be considered

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you use a mo.ui.form for this it will only run on form submission, so closer to what you probably intend

dep_b5 = mo.ui.button(**RUN_BUTTON)
dep_b6 = mo.ui.button(**RUN_BUTTON)
dep_b7 = mo.ui.button(**RUN_BUTTON)
dep_b8 = mo.ui.button(**RUN_BUTTON)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same idea for this set

MYanello
MYanello previously approved these changes May 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Comment on lines +363 to +367
if result.returncode == 0:
if not quiet:
print(f"✓ {cmd_display}")
if result.stdout.strip():
print(result.stdout.rstrip())
check: bool = False,
stream: bool = False,
timeout: int | None = None,
input: str | None = None,
Comment on lines +243 to +250
def shell( # noqa: C901
command: str | list,
quiet: bool = False,
check: bool = False,
stream: bool = False,
timeout: int | None = None,
input: str | None = None,
) -> ShellResult:
Comment on lines +599 to +628
local_context = shell("kubectl config current-context", quiet=True)
cluster_probe = None
if local_context.ok:
cluster_probe = shell("kubectl cluster-info", quiet=True, timeout=15)
if cluster_probe.ok:
# Non-fatal Python-side connectivity probe — kubectl will still work even if this fails.
try:
K8s().validate_config()
except KubernetesConfigError:
pass
return True, f"Using local kubectl context `{local_context.strip()}`."

# No local kubectl context — try in-cluster. `load_incluster_config()` is the canonical
# detection: it succeeds only when the SA token + CA + service env vars are all in place.
try:
config.load_incluster_config()
except config.ConfigException as e:
details = (
cluster_probe.stderr.strip() if cluster_probe is not None else local_context.stderr.strip()
) or str(e)
return (
False,
"kubectl is installed but no cluster context is usable. "
"If running locally, set a context with `kubectl config use-context <name>`. "
f"Details: `{details}`",
)

_write_incluster_kubeconfig(KUBECTL_INCLUSTER_KUBECONFIG_PATH)
os.environ["KUBECONFIG"] = KUBECTL_INCLUSTER_KUBECONFIG_PATH
return True, f"Using in-cluster service-account context via `{KUBECTL_INCLUSTER_KUBECONFIG_PATH}`."
Comment on lines +25 to +27
LAB_NAMESPACE = "arena-k8s-lab"
LAB_LABEL_KEY = "app.kubernetes.io/part-of"
LAB_LABEL_VALUE = "arena-k8s-lab"
Comment on lines +418 to +428
reconcile_cmd = (
f"echo '=== pods BEFORE delete ==='; "
f"kubectl -n {LAB_NAMESPACE} get pods -l app={DEPLOYMENT_NAME} -o wide; "
f"POD=$(kubectl -n {LAB_NAMESPACE} get pods -l app={DEPLOYMENT_NAME} "
f"-o jsonpath='{{.items[0].metadata.name}}'); "
f'echo; echo "=== deleting pod: $POD ==="; '
f'kubectl -n {LAB_NAMESPACE} delete pod "$POD" --wait=false; '
f"echo; echo '=== waiting 6s for the ReplicaSet controller to react ==='; sleep 6; "
f"echo; echo '=== pods AFTER delete ==='; "
f"kubectl -n {LAB_NAMESPACE} get pods -l app={DEPLOYMENT_NAME} -o wide"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants