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
podson clusterkubectl get pods -
get more info about a
podkubectl get pods -o wide -
get even more information about a
podkubectl describe pod <pod-name> -
get
podinyamlformatkubectl get pod <pod-name> -o yaml -
enter a
podkubectl exec -it <pod-name> -- /bin/bash -
create a
podkubectl run <pod-name> --image=<image-name> -
edit a
podkubectl edit pod <pod-name> -
If you are not given a
poddefinition 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
podkubectl delete pod <pod-name> -
view the containers user in a
podkubectl exec <pod-name> -- whoami
Examples đ§Š
-
simple
poddefinitionapiVersion: 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
containerspec: 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
containerspec: containers: - name: <container name> image: <image name> securityContext: runAsUser: 1000 capabilities: add: ["MAC_ADMIN"]capabiltiesare a set of linux kernel capabilities that can be added to or removed from acontainercapabilitiesare only available at thecontainerlevel, not at thepodlevel