How to docker run an image with arguments in kubernetes

10/10/2019

I want to run a kloudless docker image with the command below in kubernetes. Just wanted to know it there was any straightforward solution.

docker run -d \
  --privileged
  --tmpfs /run  --tmpfs /run/lock  --tmpfs /tmp \
  --volume /sys/fs/cgroup:/sys/fs/cgroup:ro \
  --ulimit nofile=1024000:1024000 \
  --sysctl net.ipv4.ip_local_port_range='1025 65535' \
  --name kenterprise \
  --env KLOUDLESS_CONFIG="$(cat kloudless.yml)" \
  # [ports,/data volume|db config] \
  docker.kloudless.com/prod:1.29.0  docker_entry

I know we can run docker image in kubernetes with similar configure by configuring the container in pod yaml. Example if I wanted to give --privileged argument I could

containers:
    securityContext:
      privileged: true

Just wanted to know if there are any straightforward way.

-- mad_boy
docker
kloudless
kubernetes

1 Answer

10/10/2019

kubectl run used to exist. It was probably what you were looking for. But it is depecrated now.

kubectl run -i --tty load-generator --image=busybox /bin/sh

The closest thing to running a pod/deployment from the command line without creating a file I could find is kubectl create

kubectl create deployment prod --image=busybox -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: prod
  name: prod
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prod
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: prod
    spec:
      containers:
      - image: busybox
        name: busybox
        resources: {}
status: {}

Although, I would strongly advise against running one off commands like this as it goes against the concept of infrastructure as code which Kubernetes encourages through the use of manifests.

Using manifests in a Version Control System such as git allows you to explore the history of your commands and deployments easily and manage branches of changes to your deployment.

However, if what you are looking to do is abstract your deployment so that users don't have to get their hands dirty with the internals, then I would recommend a tool like Helm, which allows you to create charts and change simple values at release time like so:

helm install --set foo=bar ./mychart

-- yosefrow
Source: StackOverflow