Score:1

SSH into GKE Kubernetes cluster?

ae flag

I have a GKE Kubernetes cluster that I would like to debug.

Is it possible to start a container inside the cluster using e.g. ubuntu image and SSH into it with full privileges, so I will be able to install software inside it with apt and run various debugging commands?

Score:5
cn flag

First of all it's possible to deploy a pod with a single container consisting of ubuntu targeting a namespace or even a node.

Rather than using SSH to connect to it (which is possible using an extensive combination of either using a LoadBalancer or exposing a NodePort) it's easier to use the kubectl tool.

If you're using Cloud Shell it's already installed or if using local laptop you have to install it using the gcloud tool.

I would suggest connecting to the container directly using the following syntax:

# Run bash on Ubuntu container
kubectl exec -it ubuntu -- bash

# General syntax
kubectl -n {namespace} exec -it {pod-name} -- {command}

First command assumes the container name is ubuntu and in the current namespace. The second command gives the general format.

Example ubuntu pod definition:

apiVersion: v1
kind: Pod
metadata:
  name: ubuntu
  labels:
    app: ubuntu
spec:
  containers:
  - image: ubuntu
    command:
      - "sleep"
      - "604800"
    imagePullPolicy: IfNotPresent
    name: ubuntu
  restartPolicy: Always

You can add a namespace to it or ensure you have the right context before applying. Something like:

kubectl apply -f path/to/yaml/file
ae flag
Thanks, could you also add an example of such pod creation? Is it possible to do in a single command without the need to create a manifest file beforehand?
cn flag
Updated with pod example.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.