简体   繁体   English

需要在Kubernetes Pod中使用CURL二进制文件

[英]Need a CURL binary availble inside kubernetes pod

I would like to sh myself inside a kubernetes pod and execute a CURL command. 我想将自己放在kubernetes容器中并执行CURL命令。 Unfortunatly I can't find anywhere a working image with curl availble (and compatible with kubernetes)... 不幸的是,我在任何地方都找不到可以卷曲的工作图像(并且与kubernetes兼容)...

  1. I tried some docker images with Alpine and CURL but each time it ended with crashLoopBackOff. 我用Alpine和CURL尝试了一些docker镜像,但是每次以crashLoopBackOff结尾。 I guess it means the container exited because the docker image exits after executing itself... 我想这意味着容器已退出,因为docker映像在执行自身后退出了...
  2. I also tried using the image of alpine and ubuntu alone but each time it also ended with crashloopBackOff. 我也尝试过单独使用alpine和ubuntu的图像,但是每次都以crashloopBackOff结尾。
  3. I manage to exec in a few images but it never had CURL installed and neither APT-GET or APK were working. 我设法在一些图像中执行,但从未安装CURL,APT-GET或APK均未运行。

To exec into a container I'm doing a simple kubectl exec -it POD_ID /bin/bash 要执行到容器中,我正在做一个简单的kubectl exec -it POD_ID /bin/bash

Does someone knows of a minimal docker image that contains a CURL binary and wont crash in kubernetes ? 有人知道包含CURL二进制文件且不会在kubernetes中崩溃的最小docker镜像吗?

PS: This is for testing purpose so it does not need to be rock solid or anything PS:这是出于测试目的,因此不需要坚如磐石或其他任何东西

Thx 谢谢


UPDATE 1 This is the yaml I use to deploy all potential image : 更新1这是我用来部署所有潜在映像的yaml:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: blue
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: blue
    spec:
      containers:
      - name: blue-website
        image: SOME_IMAGE:latest
        resources:
          requests:
            cpu: 0.1
            memory: 200

I don't think that its broken because it works on certain image. 我不认为它坏了,因为它适用于某些图像。

You can skip the manifest and use kubectl run to spin up one of these pods on demand. 您可以跳过清单,并使用kubectl run按需启动其中一个Pod。 ie

kubectl run curl -it --rm --image=tutum/curl -- sh

This would create a deployment named curl from the tutum/curl image and give you an interactive ( -it ) shell inside it. 这将根据tutum/curl映像创建一个名为curl的部署,并在其中提供一个交互式( -it )shell。 When you exit, the deployment will be deleted ( --rm ). 退出时,部署将被删除( --rm )。

You can use this image nightfury1204/alpine-curl 您可以使用此图像nightfury1204/alpine-curl

I created above image for my own testing purpose. 我出于自己的测试目的创建了以上图像。

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: curl
  labels:
    name: curl
spec:
  serviceName: "curl"
  selector:
    matchLabels:
      app: curl
  replicas: 1
  template:
    metadata:
      labels:
        app: curl
    spec:
      containers:
      - name: curl
        image: nightfury1204/alpine-curl
        command:
          - "sh"
          - "-c"
          - >
            while true; do
              sleep 3600;
            done

To exec into the pod use this kubectl exec -it curl-0 sh 要执行到pod中,请使用此kubectl exec -it curl-0 sh

You getting CrashLoopBackOff because container completes after starting as it does not have any task to process. 之所以得到CrashLoopBackOff是因为容器在启动后完成,因为它没有任何要处理的任务。 Easy workaround is to run a command in the container to keep it running indefinitely. 一种简单的解决方法是在容器中运行命令以使其无限期运行。 So that you can exec into the container and run curl. 这样您就可以执行到容器中并运行curl了。

Here, is modified yaml to do this: 在这里,修改后的yaml可以做到这一点:

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  name: blue
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
        name: blue
    spec:
      containers:
      - name: blue-website
        image: scrapinghub/httpbin:latest
        command:
        - sleep
        - "3600"
        resources:
          requests:
            cpu: 0.1
            memory: 200

Use byrnedo/alpine-curl image from https://hub.docker.com/r/byrnedo/alpine-curl/ . 使用byrnedo/alpine-curl从图像https://hub.docker.com/r/byrnedo/alpine-curl/ Also it's not neccessary to have latest tag in the deployment. 同样,在部署中不必具有latest标签。 It works without it, just 没有它就可以工作,只是

containers:
  - name: blue-website
    image: byrnedo/alpine-curl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM