Running databases? Check this interesting comparison
Headless services in Kubernetes Vs Regular Service: What, Why, and How?
Balkrishna Pandey ・ Jul 15 '22 ・ 6 min read
--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
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: {}
--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
Output if resource already exists,
Error from server (AlreadyExists): pods "nginx" already exists
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
--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
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
at the same time it create the resource as well. Run following command,
kubectl get pods
Output:
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 0 61s
Top comments (0)