Goglides Dev 🌱

Balkrishna Pandey
Balkrishna Pandey

Posted on • Updated on

--dry-run, client vs server vs none

Running databases? Check this interesting comparison

--dry-run=client -o yaml

--dry-run=client -o yaml is used to get the yaml output of the dry-run command. This is useful to see what the command will do without actually running it. The object is not validated by the apiserver.

kubectl run nginx --image=nginx --port=80 --labels="run=nginx" --restart=Never  --dry-run=client -o yaml
Enter fullscreen mode Exit fullscreen mode

Output:

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

--dry-run=server -o yaml

--dry-run=server -o yaml is used to get the yaml output of the dry-run command. If server strategy, submit server-side request without persisting the resources. The object is validated by the apiserver.

kubectl run nginx --image=nginx --port=80 --labels="run=nginx" --restart=Never  --dry-run=server -o yaml
Enter fullscreen mode Exit fullscreen mode

Output if resource already exists,

Error from server (AlreadyExists): pods "nginx" already exists
Enter fullscreen mode Exit fullscreen mode

Output if resource doesn't exists,

apiVersion: v1
kind: Pod
metadata:
  annotations:
    openshift.io/scc: anyuid
  creationTimestamp: "2022-06-24T21:11:51Z"
  labels:
    run: nginx
  name: nginx
  namespace: sno02
  uid: a18faec1-0638-4152-a83f-e699d1a73558
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: nginx
    ports:
    - containerPort: 80
      protocol: TCP
    resources: {}
    securityContext:
      capabilities:
        drop:
        - MKNOD
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-57wtx
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  imagePullSecrets:
  - name: default-dockercfg-sw2zb
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Never
  schedulerName: default-scheduler
  securityContext:
    seLinuxOptions:
      level: s0:c27,c14
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-57wtx
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
      - configMap:
          items:
          - key: service-ca.crt
            path: service-ca.crt
          name: openshift-service-ca.crt
status:
  phase: Pending
  qosClass: BestEffort
Enter fullscreen mode Exit fullscreen mode

--dry-run=none -o yaml

--dry-run=none -o yaml is used to get the yaml output of the dry-run command. If none strategy, submit server-side request and presist the resources. The object is validated by the apiserver.

kubectl run nginx --image=nginx --port=80 --labels="run=nginx" --restart=Never  --dry-run=none -o yaml
Enter fullscreen mode Exit fullscreen mode

Output:

apiVersion: v1
kind: Pod
metadata:
  annotations:
    openshift.io/scc: anyuid
  creationTimestamp: "2022-06-24T21:12:07Z"
  labels:
    run: nginx
  name: nginx
  namespace: sno02
  resourceVersion: "13672719"
  uid: 95cd3a89-1d01-4819-a165-4e8b08f28f0c
spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: nginx
    ports:
    - containerPort: 80
      protocol: TCP
    resources: {}
    securityContext:
      capabilities:
        drop:
        - MKNOD
    terminationMessagePath: /dev/termination-log
    terminationMessagePolicy: File
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-mbjdb
      readOnly: true
  dnsPolicy: ClusterFirst
  enableServiceLinks: true
  imagePullSecrets:
  - name: default-dockercfg-sw2zb
  preemptionPolicy: PreemptLowerPriority
  priority: 0
  restartPolicy: Never
  schedulerName: default-scheduler
  securityContext:
    seLinuxOptions:
      level: s0:c27,c14
  serviceAccount: default
  serviceAccountName: default
  terminationGracePeriodSeconds: 30
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  volumes:
  - name: kube-api-access-mbjdb
    projected:
      defaultMode: 420
      sources:
      - serviceAccountToken:
          expirationSeconds: 3607
          path: token
      - configMap:
          items:
          - key: ca.crt
            path: ca.crt
          name: kube-root-ca.crt
      - downwardAPI:
          items:
          - fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
            path: namespace
      - configMap:
          items:
          - key: service-ca.crt
            path: service-ca.crt
          name: openshift-service-ca.crt
status:
  phase: Pending
  qosClass: BestEffort
Enter fullscreen mode Exit fullscreen mode

at the same time it create the resource as well. Run following command,

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

Output:

NAME    READY   STATUS    RESTARTS   AGE
nginx   1/1     Running   0          61s
Enter fullscreen mode Exit fullscreen mode

Top comments (0)