kubectl
Hoop can be configured to use the kubectl command line for managing resources and executing actions on workloads in Kubernetes.
Connection Configuration
Name | Type | Description |
KUBECONFIG | filesystem | A kubeconfig file with permission to exec into pods in a namespace |
Connection Command
shellhoop admin create conn k8s -a <agent> -- kubectl
The assumption is that the service account, where the agent is deployed, has the necessary permissions to interact with the Kubernetes API. Alternatively, create the connection passing your local KUBECONFIG. Example:
shellhoop admin create conn k8s \ -a <agent> \ -e b64-filesystem:KUBECONFIG=$(cat $HOME/.kube/config |base64) \ -- kubectl
How to Use
bash# view pods in the default namespace hoop exec k8s -- get pods # restart an app hoop exec k8s -- rollout restart deployment/myapp # scale up an app hoop exec k8s -- scale --replicas=3 deployment/myapp
It’s possible to narrow down the commands in distinct connections, this gives a better user experience
- Update the connection with the command bellow
shellhoop admin create conn k8s -a <agent> -- \ kubectl --namespace prod rollout
Then it’s possible
shellhoop exec k8s -- restart deployment/myapp hoop exec k8s -- undo deployment/myapp
Interactive
kubectl
provides ways of creating interactive sessions with pods. It’s possible to map these commands to Hoop to obtain interactive sessions allocating a pseudo TTY.Connection Command
shellhoop admin create conn k8s-exec -a <agent> -- \ kubectl exec --tty --stdin deployment/myapp --
How to Use
Start an interactive bash session with a deployment/pod
shellhoop connect myapp -- bash
This will open an interactive session with the deployment
myapp
. It’s possible to map any command that spawns an interactive session.Then, it’s possible to gain a rails console session
shellhoop connect myapp -- rails console
Note that
kubectl exec
is used with -tty
and --stdin
arguments. These flags are required when using hoop connect
One-off scripts
Processes can be spawned in an ad-hoc manner using
kubectl exec
. However, in some cases, an interactive shell may be overly permissive.Connection Configuration
Name | Type | Description |
KUBECONFIG | filesystem | A kubeconfig file with permission to exec into pods in a namespace |
Connection Command
shellhoop admin create conn exec-oneoff -a <agent> -- \ kubectl exec --stdin deployment/myapp --
How to Use
This example executes an one-off process using ruby.
shellhoop exec exec-oneoff -- rails runner 'puts Rails.env'
Narrowing down the exec arguments, allow passing the stdin and executing ruby scripts.
- Edit the connection command with the bellow content
shellhoop admin create conn exec-oneoff -a <agent> -- \ kubectl exec --stdin deployment/myapp -- rails runner -
Then, it’s possible
shellhoop exec exec-oneoff <<EOF myvar='Hello' puts myvar EOF
The connection now runs one-off process accepting ruby scripts from the standard input.