Automation with OpenShift Flashcards
(47 cards)
Show the “schema” of an object or its properties
oc explain deployment.status.replicas
jsonpath construct to iterate over lists in the resource
c get deployment -n openshift-cluster-samples-operator \
cluster-samples-operator -o jsonpath=’{.status.conditions[*].type}’
Get a specific item in a list using jsonpath
c get deployment -n openshift-cluster-samples-operator \
cluster-samples-operator -o jsonpath=’{.spec.template.spec.containers[0].name}’
Filter items in a list with jsonpath
oc get deployment -n openshift-cluster-samples-operator \
cluster-samples-operator -o jsonpath=’{.status.conditions[?(@.type==”Available”)].status}’
list a single property from many objects
oc get route -n openshift-monitoring \
-o jsonpath=’{.items[*].spec.host}’
print specific properties in a tabular format
oc get pod –all-namespaces -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName
With jsonpath, extract single property with multiple nesting
oc get pods -A -o jsonpath=’{.items[].spec.containers[].image}’
Extract multiple properties at different levels of nesting
oc get pods -A -o jsonpath=’{range .items[*]}’ \
‘{.metadata.namespace} {.metadata.creationTimestamp}{“\n”}’
Execute jsonpath from file
oc get nodes -o jsonpath-file=not_ready_nodes.jsonpath
Capture the host name of the web console in a variable
console=$(oc get route -n openshift-console console \
-o jsonpath=’{.spec.host}’)
Use the curl command to display the expiry date of the OpenShift Router TLS certificate
curl https://$console -k -v 2>&1 | grep ‘expire date’
Get the host names for all routes and store them in a variable
hosts=$(oc get route -A \
-o jsonpath=’{.items[*].spec.host}’)
Use curl to get the HTTP status for each route
locate the name of the secret that contains the users
oc get oauth cluster -o json
extract the secret name from the identity provider named htpasswd_provider
filter=’?(.name==”htpasswd_provider”)’
oc get oauth cluster -o jsonpath=”{.spec.identityProviders[$filter].htpasswd.fileData.name}{‘\n’}”
Where does OCP store service account token
In the running pod under /var/run/secrets/kubernetes.io/serviceaccount/token
How do you get an operational script to authenticate with OCP
Create a service account for the purpose
service accounts belong to a namespace yes or no?
yes
CR for creating a service account
Why prefer using CR vs oc cli
declarative YAML or JSON text files encourages the DevOps practices of version control and code review
By default, the service account does not have permission to make requests to the OpenShift API server. True or False?
True.
roles and role bindings must be defined for the sa
Roles are namespaced. True or False?
True
ClusterRoles are namespaced. True or False?
True
RoleBinding are namespaced. True or False?
True