Main Flashcards
Imperative Command for Creating a Pod
kubectl run nginx –image=nginx
Imperative Command for Creating a Deployment
kubectl create deployment –image=nginx nginx
How do commands and arguments in Kubernetes overwrite what’s written in the DockerFile?
The attribute, “command:[“sleep2.0”]” inside the containers attribute overwrites the Docker command: ENTRYPOINT[“sleep”]. Same thing with args:[“10”] overwriting CMD[“5”]
Create a command defined in Kubernetes that will execute once a container has launched
containers:
- name: ubuntu
image: ubuntu
command: [“sleep”]
args: [“10”]
How does one use ConfigMaps/Secrets?
- Create ConfigMap Object
2. Attach ConfigMap Object to Pod
How do you define environment variables in a pod (No configmap)?
env:
- name: APP_COLOR
value: PINK
How do you attach a ConfigMap object to a pod?
containers: - name: simple-webapp image: simple-webapp envFrom: - configMapRef: name: {NameOfConfigMap}
How do you add a pod/deployment/replicaset to a namespace (2 methods)?
- Using imperative command: –namespace={namespace}
2. Adding namespace dictionary value to metadata attribute in yaml config
What has the –dry-run command changed to?
–dry-run=client
How do you format secret object values (2 methods)?
- Imperative commands: kubectl create secret –from-literal=key:value –from-literal=key2:value2
- a. Linux commands: echo -n ‘{secret}’ | base64 –decode
b. kubectl create -f
c.
data:
secret: decodedvalue
How do you attach a Secret object to a container?
containers: - name: simple-webapp image: simple-webapp envFrom: - secretRef: name: {nameOfSecretObject}
How do you attach a Secret to a pod (in pod definition)?
env: - name: {secretName} valueFrom: secretKeyRef: name: app-secret key: {secretValue}
How do you attach a Secret to a pod (using volumes)?
volumes:
- name: app-secret-volume
secret:
secretName: app-secret
How do you check who’s listed as the security context for running a particular container?
- kubectl exec ubuntu-sleeper – whoami
2. Do an -o yaml and see security context
How do you format a security context for a pod?
spec:
securityContext:
runAsUser: 1000
runAsGroup: 2000
How do you format a security context object for a container?
spec: containers: - name: ubuntu image: ubuntu command ["sleep", "23"] securityContext: runAsUser: 1000 runAsGroup: 2000
Does a security context on a pod or container take precedence?
Pod security contexts overwrite container security contexts.
How do you create a service account?
kubectl create serviceaccount {serviceAccountName}
How do you get a service account token?
- Find the secret ID: kubectl describe serviceaccount {serviceAccountName}
- Describe secret with secret ID: kubectl describe secret {secretID}
How do you make a call to the kubernetes api endpoint using a service account?
- Get Service Account token (see question 20)
2. curl {endpont url} –insecure –header “Authorization: Bearer {token}”
At what level do you set resource requirements in a pod definition file?
The container level. Example:
containers: - name: simplewebapp image: simple-webapp resources: requests: memory: "1Gi" cpu: 1 limits: memory: "2Gi" cpu: 2
Can a container use more than its resource limit for cpu and memory?
If a container reaches its limit for cpu, the node will throttle the cpu. If a container reaches its limit for memory, it can go above its limit, but if it keeps doing this, the pod will be destroyed.
How do you taint a node?
kubectl taint nodes {nodeName} key:value:taintEffect
Example: kubectl taint nodes node1 app=blue:NoSchedule
What is the difference between taints and tolerations?
Taints are applied to nodes while tolerations are applied to pods. A pod needs to have x toleration in order to land on x taint.