Helpful oc / kubectl commands
This is a list of useful oc and/or kubectl commands so they won’t be forgotton. No this is not a joke…
List all pods in state Running
oc get pods --field-selector=status.phase=RunningList all pods in state Running and show there resource usage
oc get pods --field-selector=status.phase=Running -o json|jq ".items[] | {name: .metada
ta.name, res: .spec.containers[].resources}"List events sort by time created
oc get events --sort-by='.lastTimestamp'Explain objects while specifing the api version
Sometimes when you run oc explain you get a message in DESCRIPTION that this particular version is deprecated, e.g. you are running oc explain deployment and get
DESCRIPTION:
DEPRECATED - This group version of Deployment is deprecated by
apps/v1/Deployment. See the release notes for more information. Deployment
enables declarative updates for Pods and ReplicaSets.| Note the DEPRECTATED message above |
if you want to see the documentation for the object that has not been deprecated you can use
oc explain deployment --api-version=apps/v1Magic with oc set
oc set is actually a very versatile command. Studying oc set -h is a good idea, here are some examples
Set route weights when alternateBackends in a route are defined
oc set route-backends bluegreen blue=1 green=9Set resources on the command line
oc set resources dc cakephp-mysql-example --limits=memory=1Gi,cpu=200mCopyright © 2020 - 2025 Toni Schmidbauer & Thomas Jungbauer
Discussion
Comments are powered by GitHub Discussions. To participate, you'll need a GitHub account.
By loading comments, you agree to GitHub's Privacy Policy. Your data is processed by GitHub, not by this website.