首页 > 解决方案 > 如何将 shell 连接到 Kubernetes pod

问题描述

我使用 kubectl 创建了一个 pod。

我想连接到这个 pod 的端点。如何使用 kubectl 做到这一点?

标签: kuberneteskubectl

解决方案


您可以进行端口转发以从本地系统访问 pod

kubectl port-forward pods/redis-master-765d459796-258hz 7000:6379

https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/

或者你可以在正在运行的容器中获取一个 shell

kubectl exec -it pods/shell-demo -- /bin/bash

https://kubernetes.io/docs/tasks/debug-application-cluster/get-shell-running-container/


推荐阅读