Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to use the metalk8s-utils image #2995

Merged
merged 4 commits into from
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/operation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ do not have a working MetalK8s_ setup.
account_administration
cluster_and_service_configuration
cluster_monitoring
metalk8s-utils
troubleshooting
105 changes: 105 additions & 0 deletions docs/operation/metalk8s-utils.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
Using the ``metalk8s-utils`` Image
==================================
NicolasT marked this conversation as resolved.
Show resolved Hide resolved
A MetalK8s installation comes with a container image called ``metalk8s-utils``
in the embedded registry. This image contains several tools an operator can use
to analyze a cluster environment or troubleshoot various system issues.

The image can be used to create a *Pod* on a node, after which a shell inside
the container can be created to run the various utilities. Depending on the
use-case, the *Pod* could be created using the host network namespace, the host
PID namespace, elevated privileges, mounting host directories as volumes, etc.

See the ``metalk8s-utils``
:download:`Dockerfile <../../images/metalk8s-utils/Dockerfile>` for a list of
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh neat, didn't realize we could embed files for download 👍

all packages installed in the image.

A Simple Shell
--------------
NicolasT marked this conversation as resolved.
Show resolved Hide resolved
To run a ``metalk8s-utils`` container as a simple shell, execute the following
command:

.. parsed-literal::

kubectl run shell \\
--image=metalk8s-registry-from-config.invalid/metalk8s-|version|/metalk8s-utils:|version| \\
--restart=Never \\
--attach \\
--stdin \\
--tty \\
--rm

This will create a *Pod* called ``shell`` with a container running the
``metalk8s-utils`` image, and present you with a shell in this container.

.. note::

This procedure expects no other ``shell`` *Pod* to be running. Adjust the
name accordingly, or use a dedicated namespace if conflicts occur.

A Long-Running Container
------------------------
In the example above, the lifetime of the container is tied to the invocation
NicolasT marked this conversation as resolved.
Show resolved Hide resolved
of ``kubectl run``. In some situations it's more efficient to keep such
container running and attach to it (and detach from it) dynamically.

* Create the *Pod*:

.. parsed-literal::

kubectl run shell \\
--image=metalk8s-registry-from-config.invalid/metalk8s-|version|/metalk8s-utils:|version| \\
--restart=Never \\
--command -- sleep infinity

This creates the ``shell`` *Pod* including a ``metalk8s-utils`` container
NicolasT marked this conversation as resolved.
Show resolved Hide resolved
running ``sleep infinity``, effectivelly causing the *Pod* to remain alive
until deleted.

* Get a shell in the container::

kubectl exec -ti shell -- bash

.. note::

The :program:`screen` and :program:`tmux` utilities are installed in the
image for terminal multiplexing.

* Exit the shell to detach

* Remove the *Pod* once the container is no longer needed::

kubectl delete pod shell

A Shell on a Particular Node
----------------------------
To pin the *Pod* in which the ``metalk8s-utils`` container is launched to a
particular node, add the following options to a suitable ``kubectl run``
invocation::

--overrides='{ "apiVersion": "v1", "spec": { "nodeName": "NODE_NAME" } }'

.. note::

In the above, replace ``NODE_NAME`` by the desired node name.

A Shell in the Host Network Namespace
-------------------------------------
To run a ``metalk8s-utils`` container in the host network namespace, e.g.,
to use utilities such as ``ip``, ``iperf`` or ``tcpdump`` as if they're
executed on the host, add the following options to a suitable
``kubectl run`` invocation::

--overrides='{ "apiVersion": "v1", "spec": { "hostNetwork": true } }'

.. note::

If multiple ``overrides`` need to be combined, the JSON objects must be
merged.

.. todo::

- Adding tolerations for various taints when using `nodeName`
- Mounting a host directory
- Exposing Salt and containerd sockets
- Running a privileged container, exposing the host `/dev` in the container
for `parted` etc. to work
Comment on lines +101 to +105
Copy link
Contributor

Choose a reason for hiding this comment

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

As a future improvement, we could add example manifests in the ISO for each use case, and let our users kubectl apply them. Maybe using kustomize in the mix can help as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I was considering that as well. Someday ;-)