大网数据广告活动
服务器运维问答

SSH into GKE Kubernetes cluster?

· 52CE 我爱测

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…

问题原文

原帖链接 · Slava Fomin II · CC BY-SA 4.0

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?

已采纳解答

原帖链接 · fswings · CC BY-SA 4.0

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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2021-08-15)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。