In the realm of object control (OC) in Unix-like operating systems, two prominent commands often create confusion: 'oc apply' and 'oc create'. Both are used for managing Kubernetes objects, but they serve different purposes and have distinct functionalities. This article aims to demystify these commands, helping you understand when to use each.

Before delving into the intricacies of 'oc apply' and 'oc create', let's quickly recap what these commands are a part of. 'OC' or 'OpenShift Command-Line Interface' is a command-line interface to interact with the cluster. It's a powerful toolset for developers and administrators to manage containers and services in a Kubernetes cluster.

'oc apply' - Patching and Managing Resources
'oc apply' is a versatile command used to apply configuration changes to resources, including Deployments, Services, Pods, and ConfigMaps. It's like a Swiss Army knife, offering multiple functionalities under one hood.

1. Patching Resources
'oc apply' is primarily used for patching resources. Patching is an operation where you apply changes to an existing resource. It's particularly useful when you want to update a specific field without replacing the entire resource.

For instance, you might want to increase the number of replicas in a Deployment. You can achieve this by patching the 'spec.replicas' field:
oc apply -f deployment.yaml -p '{"spec":{"replicas":3}}'
2. Managing Resources
'oc apply' also manages resources. Unlike 'oc create', it doesn't create new resources; instead, it updates existing ones. If the resource doesn't exist, 'oc apply' simply fails silently.

For managing resources, you generally use 'oc apply' with a configuration file:
oc apply -f my-deployment.yaml
'oc create' - Adding New Resources
'oc create' is straightforward and mainly used for adding new resources to the cluster. It's a one-way street, focusing on creating new objects rather than updating existing ones.

1. Creating New Resources
'oc create' can create new resources from a file or interactively from stdin. It's often used with the '-f' flag followed by the path to the configuration file:









oc create -f my-deployment.yaml
Alternatively, you can create a resource from a YAML specification provided interactively:
oc create -f - < deployment.yaml
^D
2. Dry Run and Rollback
'oc create' also supports dry run, allowing you to see what would happen if you executed the command, without actually performing any changes. This is particularly useful for understanding changes before applying them:
oc create -f my-deployment.yaml --dry-run
Moreover, 'oc create' provides a rollback mechanism. If something goes awry, you can easily roll back to a previous version of the resource.
In conclusion, 'oc apply' and 'oc create' each have distinct roles in managing Kubernetes objects. 'oc apply' is your go-to command for patching and managing existing resources, while 'oc create' is used for adding new objects to the cluster. Understanding this difference will help you effectively manage your Kubernetes resources.