use*_*871 8 kubernetes visual-studio-code
Typically, if I have a remote server, I could access it using ssh, and VS Code gives a beautiful extension for editing and debugging codes for the remote server. But when I create pods in Kuberneters, I can't really ssh into the container and so I cannot edit the code inside the pod or machine. And the kuberneters plugin in VSCode does not really help because the plugin is used to deploy the code. So, I was wondering whether there is a way edit codes inside a pod using VSCode.
P.S. Alternatively if there is a way to ssh into a pod in a kuberneters, that will do too.
Pav*_* K. 15
Kubernetes + 远程开发扩展现在允许:
一定有:
所需的 vscode 扩展:
如果您的要求是“kubectl edit xxx”以使用 VSCode。
解决办法是:
对于Linux:export EDITOR='code --wait'
对于Windows:set EDITOR=code --wait
对于macOS:export EDITOR='open -a "Visual Studio Code" --wait'
它实际上很简单,但在扩展中没有很好的记录。
Pod 只是 kubernetes 中的一个部署单元,这意味着您可以调整其中的容器来接收 ssh 连接。
让我们首先获取允许 ssh 连接的 docker 映像。rastasheep/ubuntu-sshd:18.04
图像对此非常好。用它创建一个部署。
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: debugger
name: debugger
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: debugger
template:
metadata:
creationTimestamp: null
labels:
app: debugger
spec:
containers:
- name: debugger
image: rastasheep/ubuntu-sshd:18.04
imagePullPolicy: "Always"
hostname: debugger
restartPolicy: Always
Run Code Online (Sandbox Code Playgroud)
现在让我们创建一个 LoadBalancer 类型的服务,以便我们可以远程访问 pod。
---
apiVersion: v1
kind: Service
metadata:
namespace: default
labels:
app: debugger
name: debugger
spec:
type: LoadBalancer
ports:
- name: "22"
port: 22
targetPort: 22
selector:
app: debugger
status:
loadBalancer: {}
Run Code Online (Sandbox Code Playgroud)
最后通过运行获取外部ip地址kubectl get svc | grep debugger
并用它来测试ssh连接ssh root@external_ip_address
注意这个docker镜像的用户/密码分别是root/root。
更新
节点端口示例。我对此进行了测试,它可以运行ssh -p30036@ip
,但我必须启用防火墙规则才能使其工作。所以,nmap
我给你的命令就有了答案。显然,运行 kubernetes 的机器不允许奇怪端口上的入站流量。与他们交谈,以便他们可以为您提供外部 IP 地址或至少节点中的端口。
---
apiVersion: v1
kind: Service
metadata:
name: debugger
namespace: default
labels:
app: debugger
spec:
type: NodePort
ports:
- name: "ssh"
port: 22
nodePort: 30036
selector:
app: debugger
status:
loadBalancer: {}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3883 次 |
最近记录: |