<p><strong>My goal is to have a pod with a working Kubectl binary inside.</strong>  </p>

<p>Unfortunatly every kubectl image from docker hub I booted using basic yaml resulted in CrashLoopbackOff or else.  </p>

<p>Has anyone got some yaml (deployment, pod, etc) that would get me my kubectl ?</p>

<hr>

<p>I tried a bunch of images with this basic yaml there:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubectl-demo
  labels:
    app: deploy
    role: backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: deploy
      role: backend
  template:
    metadata:
      labels:
        app: deploy
        role: backend
    spec:
      containers:
      - name: kubectl-demo
        image: &lt;SOME_IMAGE&gt;
        ports:
        - containerPort: 80
</code></pre>

<p>Thx</p>

Doctor
<p>Or, you can do this. It works in my context, with kubernetes on VMs, where I know where is <code>kubeconfig</code> file. You would need to make the necessary changes, to make it work in your environment.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubectl
spec:
  replicas: 1
  selector:
    matchLabels:
      role: kubectl
  template:
    metadata:
      labels:
        role: kubectl
    spec:
      containers:
      - image: viejo/kubectl
        name: kubelet
        tty: true
        securityContext:
          privileged: true
        volumeMounts:
        - name: kube-config
          mountPath: /root/.kube/
      volumes:
      - name: kube-config
        hostPath:
          path: /home/$USER/.kube/
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: node-role.kubernetes.io/master
                operator: Exists
      tolerations:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
        operator: Exists
</code></pre>

<p>This is the result:</p>

<pre><code>$ kubectl get po
NAME                      READY   STATUS    RESTARTS   AGE
kubectl-cb8bfc6dd-nv6ht   1/1     Running   0          70s
$ kubectl exec kubectl-cb8bfc6dd-nv6ht -- kubectl get no
NAME                     STATUS   ROLES    AGE   VERSION
kubernetes-1-17-master   Ready    master   16h   v1.17.3
kubernetes-1-17-worker   Ready    &lt;none&gt;   16h   v1.17.3
</code></pre>
