Showing posts with label kubectl. Show all posts
Showing posts with label kubectl. Show all posts

Saturday, November 9, 2019

busybox docker image

https://hub.docker.com/_/busybox/

docker pull busybox
docker inspect busybox

if I see in the Config section (don't look at ContainerConfig ) the Cmd is simply "sh"

which means that if I do

kubectl run --restart=Never busybox -it --image=busybox

I simply get a shell.

If I create a pod who executes simply "env"

kubectl run --restart=Never busybox --image=busybox -- env


and then "inspect" it

kubectl get pod busybox -o yaml

I see that the container got the entry:

args:
  - env


and since the "args" are simply appended to the default command defined in the container ("If you define args, but do not define a command, the default command is used with your new arguments.")... it's equivalent to specifying:


command: ["sh", "-c"]
args: ["env"]

don't forget the "-c", otherwise you get "sh: can't open 'env': No such file or directory"


NB: if with "kubectl run" you specify --command

kubectl run busybox --image=busybox --restart=Never --command -- env

then "command" instead of "args" will be generated:

spec:
  containers:
  - command:
    - env
    image: busybox
    name: busybox


This aspect of containers/pods (how to run a command with arguments) is rather confusing and poorly engineered.





Wednesday, July 10, 2019

kubectl generators and restart option

https://kubernetes.io/docs/reference/kubectl/conventions/#generators

the only non-deprecated generatori is "run-pod/v1" :

kubectl run nginx --image=nginx --generator=run-pod/v1 --dry-run -o yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    imagePullPolicy: IfNotPresent
    name: nginx
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}



kubectl run nginx --image=nginx --dry-run -o yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      run: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}



#create nginx POD only

kubectl run nginx --image=nginx --port=80 --restart=Never --dry-run -o yaml

apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    imagePullPolicy: IfNotPresent
    name: nginx
    ports:
    - containerPort: 80
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}


#create deployment nginx and pod

kubectl run nginx --image=nginx --port=80 --restart=Always --dry-run -o yaml

apiVersion: apps/v1beta1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      run: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
        resources: {}
status: {}