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.

an image of two cartoon faces with the caption the oc and the creator
an image of two cartoon faces with the caption the oc and the creator

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.

an image of two cartoon characters with the words oc and creator in front of them
an image of two cartoon characters with the words oc and creator in front of them

'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.

oc challenge/ of and creator
oc challenge/ of and creator

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.

two different faces with the words the oc and the creator
two different faces with the words the oc and the creator

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.

Draw This With Your Oc, Draw Your Ocs Over This Meme, My Oc Card, Gacha Template, Draw Your Oc Meme Template, Draw Your Characters Over This, Memes To Draw Ocs, Creator And Oc Trend Base, Oc Template Base Art
Draw This With Your Oc, Draw Your Ocs Over This Meme, My Oc Card, Gacha Template, Draw Your Oc Meme Template, Draw Your Characters Over This, Memes To Draw Ocs, Creator And Oc Trend Base, Oc Template Base Art

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.

two cartoon faces with the words the creator and the oc in black and white
two cartoon faces with the words the creator and the oc in black and white

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:

an info sheet showing the different types of people in each body and how to use them
an info sheet showing the different types of people in each body and how to use them
an image of a diagram with the words creator and oc on it in different languages
an image of a diagram with the words creator and oc on it in different languages
:p
:p
Remake
Remake
someone plzd draw this as their oc and then i'm going to do something
someone plzd draw this as their oc and then i'm going to do something
an image of two cartoon characters one is the oc and the other is the creator
an image of two cartoon characters one is the oc and the other is the creator
Challenge 26 (You can use this if you want)
Challenge 26 (You can use this if you want)
The OC ! || The creator...
The OC ! || The creator...
idk
idk

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.