使用 Kustomize 或 kubectl 从命令行部署 1 容器 pod 或服务

发布于 2025-01-20 02:20:00 字数 898 浏览 1 评论 0 原文

Kubernetes非常新。 过去

  1. 在 。

resources:
  - my-app-service.yml

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
  ... etc.
  1. 从命令行中,我将运行以下内容:
kubectl apply -k /path/to/the/kustomization.yml

如果一切顺利 - boom - 我的群集上的服务运行。 Neato。

我现在正在尝试对某些内容进行故障排除,并想部署一个 我的群集上的图像,以便我可以进入其中并进行一些与网络/授权相关的测试。

这个想法是:

  1. 部署
  2. ssh,进行测试
  3. 删除容器/清洁

i labes k8s k8s不处理容器,因此我可能需要部署1个container pod或服务(在那里的区别不清楚),但是您明白了。

i 可以创建2个yaml文件,然后像我对其他所有事情一样在它们上运行 kubectl应用... ,但这感觉有些沉重。我想知道是否有一种更简单的方法可以从命令行中完成所有操作,而无需每次我想做这样的测试时都必须创建YAML文件。 有吗?

Very new to Kubernetes. In the past I've used kubectl/Kustomize to deploy pods/services using the same repetitive pattern:

  1. On the file system, in my project, I'll have two YAML files such as kustomization.yml and my-app-service.yml that look something like:

kustomization.yml

resources:
  - my-app-service.yml

my-app-service.yml

apiVersion: v1
kind: Service
metadata:
  name: my-app-service
  ... etc.
  1. From the command-line, I'll run something like the following:
kubectl apply -k /path/to/the/kustomization.yml

And if all goes well -- boom -- I've got the service running on my cluster. Neato.

I am now trying to troubleshoot something and want to deploy a single container of the google/cloud-sdk image on my cluster, so that I can SSH into it and do some network/authorization-related testing.

The idea is:

  1. Deploy it
  2. SSH in, do my testing
  3. Delete the container/clean it up

I believe K8s doesn't deal with containers and so I'll probably need to deploy a 1-container pod or service (not clear on the difference there), but you get the idea.

I could just create 2 YAML files and run the kubectl apply ... on them like I do for everything else, but that feels a bit heavy-handed. I'm wondering if there is an easier way to do this all from the command-line without having to create YAML files each time I want to do a test like this. Is there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相思碎 2025-01-27 02:20:00

您可以使用此命令创建一个带有给定图像的容器的POD:

kubectl run my-debug-pod --image=google/cloud-sdk

如果您想在不编写YAML的情况下创建部署,则可以这样做:

kubectl create deployment my-app --image=my-container-image

您也可以仅生成YAML并将其保存为文件,然后使用<<代码> kubectl apply -f deployment.yaml ,以:

kubectl create deployment my-app --image=my-container-image \ 
--dry-run=client -o yaml > deployment.yaml

You can create a pod running a container with the given image with this command:

kubectl run my-debug-pod --image=google/cloud-sdk

And if you want to create a Deployment without writing the Yaml, you can do:

kubectl create deployment my-app --image=my-container-image

You could also just generate the Yaml and save it to file, and then use kubectl apply -f deployment.yaml, generate it with:

kubectl create deployment my-app --image=my-container-image \ 
--dry-run=client -o yaml > deployment.yaml
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文