Kubernetes - Pods đđŗđđŗ
Description đ
A pod
is a single instance of an application and is the simplest object you can create in Kubernetes
, usually have a 1:1 relationship with containers
. Pods
can have multiple containers
, but they are usually containers
of different types that are tightly coupled.
Basic Commands
đ
-
get minimal info about
pods
on clusterkubectl get pods
-
get more info about a
pod
kubectl get pods -o wide
-
get even more information about a
pod
kubectl describe pod <pod-name>
-
get
pod
inyaml
formatkubectl get pod <pod-name> -o yaml
-
enter a
pod
kubectl exec -it <pod-name> -- /bin/bash
-
create a
pod
kubectl run <pod-name> --image=<image-name>
-
edit a
pod
kubectl edit pod <pod-name>
-
If you are not given a
pod
definition file, you may extract the definition to a file using the below command, then edit the file to make the necessary changes, delete and re-create thepod
.kubectl get pod <pod-name> -o yaml > pod-definition.yaml
-
delete a
pod
kubectl delete pod <pod-name>
-
view the containers user in a
pod
kubectl exec <pod-name> -- whoami
Examples đ§Š
-
simple
pod
definitionapiVersion: v1 # kind refers to the type of object that will be created kind: Pod # data about the data that will be created metadata: name: myapp-pod labels: app: myapp type: testing # specification section, providing additional information to Kubernetes about the object spec: containers: - name: nginx-container image: nginx
-
define environment variables for a
container
spec: containers: - name: <container name> image: <image name> env: - name: DEMO_GREETING value: "Hello from the environment" - name: DEMO_FAREWELL value: "Such a sweet sorrow"
-
define security context for a
container
spec: containers: - name: <container name> image: <image name> securityContext: runAsUser: 1000 capabilities: add: ["MAC_ADMIN"]
capabilties
are a set of linux kernel capabilities that can be added to or removed from acontainer
capabilities
are only available at thecontainer
level, not at thepod
level