Automation with OpenShift Flashcards

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

A
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?

A

True

23
Q

ClusterRoles are namespaced. True or False?

A

True

24
Q

RoleBinding are namespaced. True or False?

A

True

25
Q

What are valid subjects for role binding?

A

users, groups, or service accounts.

26
Q

How do you create a binding?

A

oc policy add-role-to-user

27
Q

Cron Job CR

A
28
Q

Job CR

A
29
Q

What are container script deployment strategies?

A

1) container command
2) volume
3) container image

30
Q

Explain the container command script deployment strategy

A

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
Q

Explain the volume script deployment straregy

A

Mount a ConfigMap or persistent storage as a volume.

32
Q

Explain the image script deployment strategy

A

Package the script in a container image with all necessary dependencies. Use a GitOps pipeline with build, test, and deployment automation.

33
Q

get jobs in all namescapes

A

oc get jobs -A

34
Q

curl command to get api version

A

curl -k –header “Authorization: Bearer $(oc whoami -t)” $(oc whoami –show-server)/api

35
Q

Find the list of APis using curl

A

curl -k –header “Authorization: Bearer $(oc whoami -t)” $(oc whoami –show-server)/apis

36
Q

Create a project using REST API

A

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
Q

Content of json file for creating a project

A

{
“apiVersion”: “project.openshift.io/v1”,
“kind”: “Project”,
“metadata”: {
“name”: “example”
}
}

38
Q

Ansible OCP modules

A

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
Q

Ansible block to configure defauts

A
40
Q

Ansible play to login into OCP

A
41
Q

Ansible task to create objects from file

A
42
Q

Ansible task to get info about Pods that are web apps in dev or test

A
43
Q

Ansible task to scale up deployment

A
44
Q

Ansible task to expose https port with ClusterIP

A
45
Q

Prequisites for CP ansible modules

A

1) openshift >= 0.6.2
2) PyYAML >= 3.11
3) urllib3
4) requests
5) requests-oauthlib

46
Q

Ansible playbook to get route info

A
47
Q

Ansible task a URL and print the response code

A