KodeCloud CKAD Misc
Links: 111 KodeCloud Index
Doing dry runs
k apply -f dep.yaml --dry-run=client
This will not create the resource, instead, tell you whether the resource can be created and if your command is right.
-
Output the yaml files of imperative commands
k run nginx --image=nginx --dry-run=client -o yaml
- Other imperative commands are create (creating a service, creating a deployment, etc), expose etc.
-
Get the yaml file for any resource:
k get <resource-type> <resource-name> -o yaml > definition.yaml
- This is useful when you have already defined resources in a cluster and you don't have their yaml files.
-
Formatting the output:
-o json
: Output a JSON formatted API object.-o name
: Print only the resource name and nothing else.-o wide
: Output in the plain-text format with any additional information.-o yaml
: Output a YAML formatted API object.
-
Forcefully apply a file
k apply -f --force <file-name>.yaml
-
Get objects from all the namespaces:
k get <resource-name> -A
- Example:
k get pods -A
- Get all the objects in all namespaces:
k get all -A
-
Service full DNS:
<svc-name>.<namespace>.svc.cluster.local
- We can remove the headers from the output of any command using:
k <command> --no-headers
If we want to get the short names or api version or kind or find out whether they are namespaced or not we can use k api-resources
Long form: k api-resource -o wide
What happens when you do k get pods
- The request goes to the kubeapi-server.
- When the request hits the kubeapi-server it goes through an authentication process and this is done using certificates.
- If the request was sent using kubectl then we know that the kubeconfig file has the required certificates configured.
- After authentication the request goes through and authorisation process. This is achieved using RBAC.
- If the user is allowed to list the pods then he will be able to list the pods.
-
If the scheduler can't schedule the pod then it will go into PENDING state.
-
Get all the events in a namespace:
k get events
- Describing the api-server pod for important details
k get pods -n kube-system
k describe pod/kube-apiserver-controlplane -n kube-system
- It may be named differently depending on how it is setup.
Last updated: 2023-05-10