Page
Import objects into a cluster
Moving objects from one cluster to another involves an export and an import. The import step in between is to remove unwanted objects.
In order to get full benefit from taking this lesson, you need to:
- Have access to the OpenShift dashboard.
- Have access to a command line to run the
oc
command.
In this lesson, you will:
- Remove unwanted objects from your YAML files.
- Import objects at the command line.
Remove unwanted objects
Unzip the exported objects into a directory, then navigate to that directory. There will be several YAML files, some of which are not related to your application. Inside the YAML files, a label identifies the files that are related to your application, in the form of app.kubernetes.io/part-of
: {your_application_name_goes_here
} Those are the files you want to import.
Remain in the directory. Log in to your cluster from the command line and run the following command:
If using PowerShell:
Remove-Item (gci | Where-Object { !( $_ | Select-String "app.kubernetes.io/part-of: {your_application_name_goes_here}" -quiet) })
If using Bash shell:
grep -L "app.kubernetes.io/part-of: {your_application_name_goes_here}" * | xargs rm
This will reduce the number of files in the directory from several dozen to just a few.
Import objects
Import the objects with one command:
oc apply -f .
Summary
You now know how to remove unwanted objects from your list of objects and then import the remaining objects.
Want to learn more? Try these:
- OpenShift for Developers e-book.
- Numerous cheat sheets.