DEV Community

Naveen Jayachandran
Naveen Jayachandran

Posted on

Kubernetes - Images

A container image represents binary data used to encapsulate an application and all its software dependencies. Container images can be thought of as executable software bundles that run independently and make specific assumptions about their runtime environment.

Typically, we create a container image of our application and push it to a registry before deploying it as a Pod.

Image Names
Container images can have names such as pause, kube-apiserver, or example/mycontainer.
They can also include registry hostnames — for example:
fictional.registry.example/imagename
or even port numbers, such as
fictional.registry.example:10443/imagename.

If no registry hostname is specified, Kubernetes assumes the image is hosted on the Docker public registry.

After the image name, we can add a tag.
Tags are used to identify different versions of the same image series.
Tags can include lowercase and uppercase letters, periods (.), dashes (-), and underscores (_).
If no tag is specified, Kubernetes automatically uses the latest tag.

Image Config File
apiVersion: v1
kind: Pod
metadata:
name: AskTech
spec:
containers:
- name: asktech-image
image:
imagePullPolicy: Always
command: ["echo", "SUCCESS"]
Understanding the Config File
name: AskTech → The name of the Pod that will be created after pulling the image from the registry.

name: asktech-image → The name given to the container that we want to create.

image: → The name of the image that needs to be pulled from the Docker Registry.

imagePullPolicy: Always → This policy ensures the image is pulled from the registry every time the Pod is created.

command: ["echo", "SUCCESS"] → Displays a success message when the container starts successfully.

Image Commands
To pull the image and create a container:

$ kubectl create -f
To check the logs:

$ kubectl logs Testing_for_Image_pull
Image Updating
When creating a StatefulSet, Pod, or Deployment, if the imagePullPolicy is not explicitly defined, it defaults to IfNotPresent.
This means that Kubelet will not re-pull the image if it already exists locally.

The imagePullPolicy determines when Kubernetes downloads or pulls the image.
The possible values are:

IfNotPresent → Pulls the image only if it’s not already present on the node.

Always → Always pulls the image, even if it exists locally.

Never → Never pulls the image; uses only the local copy.

Be cautious when using image tags like latest — if the registry updates the image with new code under the same tag, you might end up with Pods running mixed versions of the application (old and new code).

Top comments (0)