Automation with OpenShift Flashcards

(47 cards)

1
Q

Show the “schema” of an object or its properties

A

oc explain deployment.status.replicas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

jsonpath construct to iterate over lists in the resource

A

c get deployment -n openshift-cluster-samples-operator \
cluster-samples-operator -o jsonpath=’{.status.conditions[*].type}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Get a specific item in a list using jsonpath

A

c get deployment -n openshift-cluster-samples-operator \
cluster-samples-operator -o jsonpath=’{.spec.template.spec.containers[0].name}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Filter items in a list with jsonpath

A

oc get deployment -n openshift-cluster-samples-operator \
cluster-samples-operator -o jsonpath=’{.status.conditions[?(@.type==”Available”)].status}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

list a single property from many objects

A

oc get route -n openshift-monitoring \
-o jsonpath=’{.items[*].spec.host}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

print specific properties in a tabular format

A

oc get pod –all-namespaces -o=custom-columns=NAME:.metadata.name,STATUS:.status.phase,NODE:.spec.nodeName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

With jsonpath, extract single property with multiple nesting

A

oc get pods -A -o jsonpath=’{.items[].spec.containers[].image}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Extract multiple properties at different levels of nesting

A

oc get pods -A -o jsonpath=’{range .items[*]}’ \
‘{.metadata.namespace} {.metadata.creationTimestamp}{“\n”}’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Execute jsonpath from file

A

oc get nodes -o jsonpath-file=not_ready_nodes.jsonpath

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Capture the host name of the web console in a variable

A

console=$(oc get route -n openshift-console console \
-o jsonpath=’{.spec.host}’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Use the curl command to display the expiry date of the OpenShift Router TLS certificate

A

curl https://$console -k -v 2>&1 | grep ‘expire date’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Get the host names for all routes and store them in a variable

A

hosts=$(oc get route -A \
-o jsonpath=’{.items[*].spec.host}’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Use curl to get the HTTP status for each route

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

locate the name of the secret that contains the users

A

oc get oauth cluster -o json

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

extract the secret name from the identity provider named htpasswd_provider

A

filter=’?(.name==”htpasswd_provider”)’

oc get oauth cluster -o jsonpath=”{.spec.identityProviders[$filter].htpasswd.fileData.name}{‘\n’}”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Where does OCP store service account token

A

In the running pod under /var/run/secrets/kubernetes.io/serviceaccount/token

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you get an operational script to authenticate with OCP

A

Create a service account for the purpose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

service accounts belong to a namespace yes or no?

A

yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

CR for creating a service account

20
Q

Why prefer using CR vs oc cli

A

declarative YAML or JSON text files encourages the DevOps practices of version control and code review

21
Q

By default, the service account does not have permission to make requests to the OpenShift API server. True or False?

A

True.
roles and role bindings must be defined for the sa

22
Q

Roles are namespaced. True or False?

23
Q

ClusterRoles are namespaced. True or False?

24
Q

RoleBinding are namespaced. True or False?

25
What are valid subjects for role binding?
users, groups, or service accounts.
26
How do you create a binding?
oc policy add-role-to-user
27
Cron Job CR
28
Job CR
29
What are container script deployment strategies?
1) container command 2) volume 3) container image
30
Explain the container command script deployment strategy
Specify short Bash scripts as arguments to a container in the spec. This method is easy to deploy, but makes reviewing and automated tests more difficult.
31
Explain the volume script deployment straregy
Mount a ConfigMap or persistent storage as a volume.
32
Explain the image script deployment strategy
Package the script in a container image with all necessary dependencies. Use a GitOps pipeline with build, test, and deployment automation.
33
get jobs in all namescapes
oc get jobs -A
34
curl command to get api version
curl -k --header "Authorization: Bearer $(oc whoami -t)" $(oc whoami --show-server)/api
35
Find the list of APis using curl
curl -k --header "Authorization: Bearer $(oc whoami -t)" $(oc whoami --show-server)/apis
36
Create a project using REST API
curl -k --header "Authorization: Bearer qfyV5ULvv...i712kJT" \ --header 'Content-Type: application/json' -d "$(< project.json)" \ -X POST https://api.example.com/apis/project.openshift.io/v1/projects
37
Content of json file for creating a project
{ "apiVersion": "project.openshift.io/v1", "kind": "Project", "metadata": { "name": "example" } }
38
Ansible OCP modules
1) k8s: manages k8s objects, allowing you to create, update, or delete Kubernetes objects 2) k8s_auth: returns api_key that other modules can use 3) k8s_info: Retrieves info about k8s objects 4) k8s_scale: sets new sizes for a Deployment, ReplicaSet, rc, or Job 5) k8s_service: manages services on k8s
39
Ansible block to configure defauts
40
Ansible play to login into OCP
41
Ansible task to create objects from file
42
Ansible task to get info about Pods that are web apps in dev or test
43
Ansible task to scale up deployment
44
Ansible task to expose https port with ClusterIP
45
Prequisites for CP ansible modules
1) openshift >= 0.6.2 2) PyYAML >= 3.11 3) urllib3 4) requests 5) requests-oauthlib
46
Ansible playbook to get route info
47
Ansible task a URL and print the response code