CKA Study Flashcards

1
Q

Command: Apply configuration changes to a resource

A

kubectl apply -f FILENAME

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

Command: Access a web server via a NodePort

A

curl http://<Node>:<NodePort>
ie: http://198.168.1.2:30008</NodePort></Node>

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

Command: Create a resource

A

kubectl create -f FILENAME

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

Command: Creating a file from a Deployment

A

kubectl create deployment –image=nginx nginx –dry-run=client -o yaml > nginx-deployment.yaml

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

Command: Edit and update the definition of a resource

A

kubectl edit (-f FILENAME | TYPE NAME)

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

Command: Get documentation for a resource type

A

kubectl explain RESOURCE-TYPE

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

Command: Replace a resource

A

kubectl replace –force -f FILENAME

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

Command: Update the size of the specified replication controller

A

kubectl scale -f FILENAME

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

Command: Change the ETCD API version for commands

A

If you get the message, “No help topic for …”

export ETCDCTL_API=3 (default is 2)

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

Command: Execute a command against an resource

A

kubectl exec etcd-master -n kube-system etcdctl get / –prefix - keys-only

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

Command: List Pods

A

kubectl get pods

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

Command: Display the detailed state of a Pod

A

kubectl describe pod <Pod> -n=NAMESPACE</Pod>

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

Command: View a running resource and its effective options

A

ps -aux | grep <Process-Name></Process-Name>

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

If a specific Controller doesn’t seem to work or exist

A

Look at the Kube-Controller-Manager options
Kubeadm: /etc/kubernetes/manifests/kube-controller-manager.yaml
Non-Kubeadm: /etc/systemd/system/kube-controller-manager.service

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

Location: Where is the Pod Definition file located

A

Kubeadm: /etc/kubernetes/manifests/kube-apiserver.yaml
Non-Kubeadm: /etc/systemd/system/kube-apiserver.service

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

Object: ETCD-Master

A

Key/Value data store
Runs on Port 2379
Can be accessed via a browser at https://<IP>:2379</IP>

Set Value: ./etcdctl set key1 value1
Get Value: ./etcdctl set key1

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

Object: Kube-APIServer

A

Authenticate User
Validate Request
Retrieve Data
Update ETCD
Used by Kube-Scheduler-Master and Kubelet

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

Object: Kube-Proxy

A

Runs on each Node in the Cluster
Look for new Services
Creates an new Rule on each Node to forward traffic to those Services

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

Object: Kube-Scheduler

A

Decides which Pod goes on which Node
Kubeadm: /etc/kubernetes/manifests/kube-scheduler.yaml
Non-Kubeadm: /etc/systemd/system/kube-scheduler.service

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

Object: Kubelet

A

Registers Node on the K8S cluster
Creates Pods
Monitors Nodes and Pods
Configuration located at /var/lib/kubelet/config.yaml

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

Object: Master Node

A

ETCD: Information on the cluster
Kube-Scheduler: Schedule applications or containers
Kube-Controller-Manager: Takes care of all controllers
Kube-APIServer: Orchestrating operations on the cluster

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

Object: Kube-Controller-Manager

A

Monitors services and brings them to the desired state

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

Object: Node-Controller

A

Monitor Nodes and keeps Pods running

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

Object: Namespace Kube-System

A

Namespace for system resources

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

Object: Namespace Kube-Public

A

Namespace for shared resources

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

Object: ResourceQuota

A

apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quota
spec:
hard:
pods: “10”
requests.cpu: “4”
requests.memory: 5Gi
limits.cpu: “10”
limits.memory: 10Gi

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

Object: ClusterIP Service

A

Creates a virtual IP to enable communication between services and pods, in the cluster

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

Object: NodePort Service

A

Listens to a port and forwards requests on that port to another port, across the cluster
- the Port is required and must be between 30000 and 32676
- if the TargetPort is not specified, it will be the same value as Port
- if the NodePort is not specified, it will be automatically assigned
NodePort services also externally exposes the IP Address

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

Object: LoadBalancer Service

A

Provisions a Load Balancer for applications

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

Object: Pods

A

A single instance of an Application
Helper Containers, supporting the Application, can be in the same Pod
There are many Pods in a Node

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

Object: Replication-Controller

A

Manages the Replicate Sets
- Pods per Set
- High Availability and Resiliency

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

Object: Worker Node

A

Container Engine: Docker (other engines are available)
Kubelet: Listens to Kube-API-Server and carries out instructions
Kube-Proxy: communication between nodes

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

YAML: Service NodePort

A

apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30008
selector:
app: myapp
type: frontend

In the Selector, app and type are copied from the Pod’s Labels section

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

YAML: Deployment

A

apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
labels:
app: myapp
tier: frontend
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
tier: frontend
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels:
type: frontend

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

YAML: Namespace

A

apiVersion: v1
kind: Namespace
metadata:
name: my-namespace

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

YAML: Pod

A

apiVersion: v1
kind: Pod
metadata:
name: my-nginx
labels:
app: nginx
tier: frontend
spec:
containers:
- name: my-nginx
image: nginx

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

YAML: ReplicaSet

A

apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: myapp-replicaset
labels: // these labels are for the ReplicaSet
app: myapp
tier: frontend
spec:
template:
metadata:
name: myapp-pod
labels: // these labels are for filtering the specific Pods
app: myapp
tier: frontend
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3
selector:
matchLabels: // these matchLabels must match the Pod filtering labels
type: frontend

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

YAML: ReplicationController

A

apiVersion: v1
kind: ReplicationController
metadata:
name: myapp-rc
labels:
app: myapp
tier: frontend
spec:
template:
metadata:
name: myapp-pod
labels:
app: myapp
tier: frontend
spec:
containers:
- name: nginx-container
image: nginx
replicas: 3

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

YAML: Service ClusterIP

A

apiVersion: v1
kind: Service
metadata:
name: backend
spec:
type: ClusterIP
ports:
- targetPort: 80
port: 80
selector:
app: myapp
type: backend

In the Selector, app and type are copied from the Pod’s Labels section

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

YAML: Service LoadBalancer

A

apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
type: LoadBalancer
ports:
- targetPort: 80
port: 80
nodePort: 30008

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

Command: Create a Pod from the command line

A

kubectl run nginx –image=nginx –port=8080

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

Command: Create a Service to expose a Deployment or Pod

A

kubectl expose deployment nginx –port 80 –name nginx-service
kubectl expose pod redis –port 80 –name redis-service

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

Command: Update an Image on a Deployment

A

kubectl set image deployment nginx nginx=nginx:1.18

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

Command: Getting Help

A

kubectl create service clusterip –help

45
Q

Command: Check if the K8S components are executing

A

kubectl get nodes -n kube-system

46
Q

Command: Filter by Labels

A

kubectl get pods –selector LABEL1=VALUE1,LABEL2=VALUE2

47
Q

Command: Taints

A

Add: kubectl taint nodes NODE-NAME key=value:taint-effect
taint-effects: NoSchedule | PreferNoSchedule | MoExecute

Remove: kubectl taint nodes NODE-NAME TAINT-

48
Q

Command: Labels

A

kubectl label nodes NODE-NAME KEY=VALUE

49
Q

YAML: Node Affinity

A

apiVersion: v1
kind: Pod
metadata:
name: my-nginx
spec:
containers:
- name: my-nginx
image: nginx
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: size
operator: In
values:
- Large
- Medium

50
Q

Command: Create YAML from running resource

A

kubectl get pod PODNAME -o yaml > PODNAME.yaml

51
Q

YAML: DaemonSet

A

Same YAML as ReplicaSet, except the kind is DaemonSet

52
Q

Location: Path of the Static Pod Manifests

A

Usually, these are in /etc/kubernetes/manifests
If not, view /var/lib/kubelet/config.yaml
Look for “staticPodPath”

53
Q

Command: Viewing Docker processes

A

docker ps

54
Q

Command: Verify if a Pod is Static

A

Execute kubectl get pod NAME -o yaml
Investigate the ownerReferences section
If “kind: Node”, then it’s a static pod

55
Q

YAML: Create a Pod with an imbedded command

A

kubectl run <…> –command – sleep 100
Make sure “command” is the last parameter

56
Q

YAML: Pod with tolerations

A

Using a Pod YAML, under the “spec” section, at the same indent as “containers”, add:

tolerations:
- key: “app”
operator: “Equal”
value: “blue”
effect: “NoSchedule”

57
Q

Command: Get Events

A

kubectl get events

58
Q

Command: View Scheduler Logs

A

kubectl logs SCHEDULERNAME –name-space=kube-system

59
Q

YAML: Additional Scheduler

A

apiVersion: v1
kind: Pod
metadata:
name: my-custom-scheduler
namespace: kube-system
spec:
containers:
- command:
- kube-scheduler
- –address=127.0.0.1
- –kubeconfig=/etc/kubernetes/scheduler.conf
- –leader-elect=true
- –scheduler-name=my-custom-scheduler
- –lock-object-name=my-custom-scheduler
image: k8s.gcr.io/…
name: kube-scheduler

In /etc/kubernetes/manifests/kube-scheduler.yaml
Either change the “–leader-elect=true” to false
- or -
Add the “–lock-object-name=CustomSchedulerName”

60
Q

YAML: Using a custom scheduler

A

Using a Pod YAML, under the “spec” section, at the same indent as “containers”, add:

schedulerName: SCHEDULERNAME

61
Q

Command: View Performance

A

kubectl top Node
kubectl top pod

62
Q

Command: Install K8S Metrics Server

A

git clone https://github.com/kodekloudhub/kubernetes-metrics-server.git
kubectl create -f kubernetes-metrics-server/.

63
Q

Command: Display Logs for a Pod

A

kubectl logs -f PODNAME CONTAINERNAME –previous

64
Q

Command: App Rollout Status

A

kubectl rollout status DEPLOYMENTNAME

65
Q

Command: App Rollout History

A

kubectl rollout history DEPLOYMENTNAME

66
Q

Command: App Rollback

A

kubectl rollout undo DEPLOYMENTNAME

67
Q

YAML: Pod Command and Arguments

A

Using a Pod YAML, under the “spec” section, under the “containers” section,
at the same indent as “image”, add:

command:[“COMMAND”]
args: [“ARGUMENTS”]

68
Q

YAML: Pod Environment Variables

A

Using a Pod YAML, under the “spec” section, under the “containers” section,
at the same indent as “image”, add:

env:
- name: myVar
value: pink

69
Q

Command: Configmap

A

kubectl create configmap \
CONFIGNAME –from-literal=KEY=VALUE
–from-literal=KEY=VALUE
- OR -
kubectl create configmap \
CONFIGNAME –from-file=PATHANDFILE

70
Q

YAML: Configmap File

A

apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
KEY1: VALUE1
KEY2: VALUE2

71
Q

YAML: Pod and Configmap

A

Using a Pod YAML, under the “spec” section, under the “containers” section,
at the same indent as “image”, add:

envFrom:
- configMapRef:
name: CONFIGMAPNAME

  • OR -

env:
- name: ENVNAME
valueFrom:
configMapKeyRef:
name: CONFIGMAPNAME
key: ENVNAME

  • OR -

volumes:
- name: app-config-volume
configMap:
name: CONFIGMAPNAME
name: CONFIGMAPNAME2

72
Q

Command: Secret

A

kubectl create secret generic \
SECRETNAME –from-literal=KEY=VALUE
–from-literal=KEY=VALUE

kubectl create secret generic \
SECRETNAME –from-file=PATHANDFILE

73
Q

YAML: Secret File

A

apiVersion: v1
kind: Secret
metadata:
name: app-secret
data:
KEY1: VALUE1
KEY2: VALUE2

74
Q

Command: Base64 Encode and Decode

A

Encode: echo -n ‘VALUE’ | base64
- OR -
cat <FILENAME> | base64 -w 0
Decode: echo -n 'VALUE' | base64 --decode</FILENAME>

75
Q

YAML: Pod and Secret File

A

Using a Pod YAML, under the “spec” section, under the “containers” section,
at the same indent as “image”, add:

envFrom:
- secretRef:
name: SECRETNAME

  • OR -

env:
- name: SECRETKEYNAME
valueFrom:
configMapKeyRef:
name: SECRETNAME
key: SECRETKEYNAME

  • OR -

volumes:
- name: app-secret-volume
configMap:
name: SECRETNAME
name: SECRETNAME2

76
Q

Command: Execute within the Pod

A

kubectl exec PODNAME -it
- OR -
kubectl exec PODNAME – <command></command>

77
Q

SYSParm: Pod Eviction Timeout

A

kube-controller-manager –pod-eviction-timeout

78
Q

Command: Drain Node

A

kubectl drain NODENAME
then, kubectl uncordon NODENAME

79
Q

Command: Cordon/Uncordon Node

A

Cordon: kubectl cordon NODENAME
Uncordon: kubectl uncordon NODENAME

80
Q

Command: Alias kubectl

A

alias k=kubectl

81
Q

Command: Latest Stable K8S Version

A

kubeadm upgrade plan

82
Q

Command: Snapshot ETCD

A

Values can be found in etcd pod.

etcdctl snapshot save FILENAME.db \
–endpoints=”listen-client-urls” \ (exclude https:\)
–cacert=”trusted-ca-file” \
–cert=”cert-file” \
–key=”key-file”

View Status: etcdctl snapshot status FILENAME.db

83
Q

Command: ETCD Restore

A

a) etcdctl snapshot restore –data-dir NEWDIRECTORYNAME SNAPSHOTFILENAME
b) vi /etc/kubernetes/manifests/etcd.yaml
c) change the data-data directory in the volumes section
d) save will recreate etcd pod

84
Q

Command: Switching Context

A

1) kubectl config view
2) kubectl config set-context –current –namespace=<NewNamespace></NewNamespace>

85
Q

YAML: Pod and Volumes

A

Using a Pod YAML, under the “spec” section, under the “containers” section,
at the same indent as “image”, add:

volumeMounts:
- mountPath: CONTAINERDIRPATH
name: VOLUMENAME

Also, at the same indent as “containers”, add:

volumes:
- name: VOLUMENAME
hostPath:
path: HOSTDIRPATH

86
Q

YALM: Persistent Volumes

A

apiVersion: v1
kind: PersistentVolume
metadata:
name: my-persist-vol
spec:
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce (must match Access in PVC)
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /pv/log

87
Q

YAML: Persistent Volume Claims

A

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: CLAIMNAME (must match CLAIMNAME in Pod)
spec:
accessModes:
- ReadWriteOnce (must match Access in PV)
resources:
requests:
storage: 500Mi

88
Q

YAML: Pods and Persistent Volume Claims

A

Using a Pod YAML, under the “spec” section, under the “containers” section,
at the same indent as “image”, add:

volumeMounts:
- mountPath: CONTAINERDIRPATH
name: VOLUMENAME

Also, at the same indent as “containers”, add:

volumes:
- name: VOLUMENAME
persistentVolumeClaim:
claimName: CLAIMNAME (must match CLAIMNAME in PVC)

89
Q

YAML: StorageClass

A

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: standard
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: Wait ForFirstConsumer

90
Q

Object: TLS Certificates

A

Three Server Certificates:
1) API Server
2) ETCD Server
3) Kubelet Server

Four Client Certificates:
1) Admin
2) Kube Scheduler
3) Kube Controller Manager
4) Kube Proxy

91
Q

Command: Inspect Service Logs

A

Kubeadm: kubectl logs etcd-master
- OR -
journalctl -u etcd.service -l
- OR -
docker ps -a
docker logs <CONTAINERID>
- OR -
crictl ps -a
crictl logs <CONTAINERID></CONTAINERID></CONTAINERID>

92
Q

Command: Approve CSR

A

kubectl certificate approve <CSRNAME></CSRNAME>

93
Q

Location: where is the default kubeconfig file ?

A

$HOME/.kube/config

94
Q

Command: API Groups URL

A

Available API Groups: http://localhost:6443 -k
Supported Resource Groups: http://localhost:6443/apis -k | grep “name”

Be aware: start kubectl proxy service so you don’t need to enter certificate info
1) kubectl proxy
2) http://localhost:8001 -k

95
Q

Location: API Server Authorization Mode

A

In /etc/kubernetes/manifests/kube-aip-server.yaml, add:
“–authorization-mode=”

96
Q

Command: RBAC

A

1) kubectl get roles
2) kubectl get rolebindings
3) kubectl describe role <ROLENAME></ROLENAME>

97
Q

Command: Check My Access

A

kubectl auth can-i create deployments –as <USERNAME></USERNAME>

98
Q

Command: Cluster Roles

A

1) kubectl get clusterroles
2) kubectl get clusterrolebindings
3) kubectl describe clusterrole <CLUSTERROLENAME></CLUSTERROLENAME>

99
Q

Command: List All Resources

A

kubectl api-resources

100
Q

Command: Service Account

A

1) kubectl create serviceaccount <SVCACCTNAME>
2) kubectl create token <SVCACCTNAME></SVCACCTNAME></SVCACCTNAME>

101
Q

Command: Private Repository

A

1) kubectl create secret docker-registry <DOCKERREGREDS> \
--docker-server= \
--docker-username= \
--docker-password= \
-- docker-email=
2) Using a Pod YAML, under the "spec" section, at the same indent as "containers" section, add:</DOCKERREGREDS>

imagePullSecrets:
- name: <DOCKERREGREDS></DOCKERREGREDS>

102
Q

Command: Install Weave Net

A

kubectl apply -f “https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d ‘\n’)”

103
Q

Object: CoreDNS

A

DNS solution
Configuration file is located at: /etc/coredns/Corefile

104
Q

Command: Return IP Address of Service or Pod

A

Service: host <SERVICENAME> (may be partially qualified)
Pod: host 10-244-2-5.default.pod.cluster.local</SERVICENAME>

105
Q

Command: View Ingress Controller

A

kubectl get ingress

106
Q

Kubeadm Steps

A

1) Provision VMs
2) Designate Master node
3) Install Docker on all nodes
4) Install kubeadm on all nodes
5) Initialize Master node
- verify IP Addr (ifconfig eth0) when creating kubeadm inti command
6) Set up networking solution (Pod Network)
7) Join Worker nodes to Master node

107
Q

Command: Check Control Plane Services

A

service kube-apiserver status

108
Q

Kubectl Cheat Sheet

A

K8S Doc&raquo_space; Reference&raquo_space; Command Line Tool&raquo_space; kubectl Cheat Sheet

109
Q

Command: Using JSON Path Queries

A

kubectl get deployments.apps
-o=custom-columns=’COLHEADER:JSONPATH,COLHEADER:JSONPATH’ –sort-by=JSONPATH
(remember to exclude “.items” portion of JSONPATH)

kubectl get deployments.apps
-o=jsonpath=’{range .items[*]}{JSONPATH}{“\t”}{JSONPATH}