Kubernetes A Hands On Task Based On Deployment 1728874761
Kubernetes A Hands On Task Based On Deployment 1728874761
Deployment
a) Creating deployment and NodePort service for pod with “docker.io/nginx” container image
Explanation:
apiVersion: Specifies the version of the Kubernetes API used for this resource.
kind: Indicates that this resource is a Deployment.
metadata: Contains identifying information about the Deployment, such as its name and
labels.
replicas: Defines the desired number of Pods to be maintained by the Deployment.
selector: Specifies the criteria for selecting Pods that the Deployment will manage.
template: Describes the structure and specifications for the Pods created by the
Deployment.
containers: Lists the containers to be run within each Pod.
name: Specifies the name of the container within the Pod.
image: Indicates the container image to be used for creating the Pods.
ports: Defines the network ports exposed by the container.
containerPort: Specifies the port that the container will listen on for incoming traffic.
Create the deployment using the above file
Now let’s Create a NodePort service to make the application accessible from outside the cluster
Create a yaml file that defines the attributes for the required service
Explanation:
apiVersion: Specifies the API version for the Service resource, indicating it is part of the core
Kubernetes API.
kind: Indicates that this resource is a Service, which provides stable access to one or more
Pods.
metadata: Contains identifying information about the Service, including its name and labels.
name: The name of the Service, used to uniquely identify it within the namespace.
labels: Key-value pairs used to organize and select resources within Kubernetes.
app: A label indicating that this Service is associated with the nginx application.
spec: Defines the desired state and configuration for the Service.
type: Specifies that the Service should be accessible externally using the NodePort type.
selector: Defines how the Service selects the Pods to route traffic to based on labels.
ports: Configures the port settings for the Service, including the exposed and forwarded
ports.
port: The port exposed by the Service for external access.
targetPort: The port on the selected Pods to which the Service should forward traffic.
nodePort: The port on each Node where the Service is accessible externally.
Thus, the application is accessible for the clients outside the cluster
b) Creating deployment and NodePort service for the pods with “quay.io/libpod/banner”
image
Creating Service:
Define the Nodeport service attributes in a YAML file
Successfully created NodePort service for the pods with “quay.io/libpod/banner” image
Thus, the application is accessible outside the cluster through port we assigned
Now write a YAML file to define all the required attributes for creating deployment that manages
pods with the container image “docker.io/pengbai/docker-supermario”
Here we will use the mentioned image in the image field and expose the port 8080 required by this
application
In the YAMl file use port number 30003 for the current deployment and make sure to use
appropriate labels for pod-service connectivity
Create service using the yaml file