You are on page 1of 7

Create Cluster Objects by Using Imperative

Commands
Create a pod by using an imperative command

Hints Enabled

No Yes
You have been automatically signed in to WS2019 as the administrator.

 Open the MobaXterm desktop application.


 Establish a new SSH session to the k8s-master1 virtual machine as the administrator
using Passw0rd! as the password, and then when prompted to save the password, select No.
Select the Type Text icon to enter the associated text into the terminal.

Expand this hint for guidance on establishing a new SSH session.


o In the sidebar, in User sessions, double-click k8s-master1.
o When prompted for a password, enter Passw0rd!, and then press Enter. You will not see the
password on the screen.
o When prompted to save the password, select No.

k8s-master1 is an Ubuntu Linux virtual machine. When you enter the password, you will not see the
password in the terminal.

This challenge contains a fully functional Kubernetes cluster environment. The k8s-master1 virtual
machine is the cluster master node and the k8s-worker1 and k8s-worker2 virtual machines are the
cluster worker nodes. All commands against the cluster will be executed on the master node by using
the Kubernetes kubectl command-line tool.

 Create a pod named pod1 that contains an nginx Docker image by using the kubectl
run command and the --image= command option.
Expand this hint for guidance on creating a pod by using the run command.
o Run the following command to create a pod named pod1:

kubectl run pod1 --image=nginx

The kubectl run command downloaded an nginx Docker image from Docker hub, deployed it to
a Docker container instance, and then encapsulated the container in the pod1 object. You use the --
image= option to specify the image that will run in the container.
The kubectl run command is an imperative command. Imperative commands are kubectl commands
that execute changes directly against an object when the object revision history is not required. You
can use an imperative command to create an object or to execute commands directly against a live
object. Imperative commands can be useful when making changes to an object; however, it is
difficult to support an infrastructure by using imperative commands because an audit trail or revision
history does not exist.

more...
 Display the status of pod1 by using the kubectl get command.
Expand this hint for guidance on displaying the status of a pod.
o Run the following command to display the status of pod1:

kubectl get pods

o The following screenshot shows the result of the kubectl get pods command:

 Create a pod named pod2 that contains a redis Docker image and
a label named tier=database by using the kubectl run command and the --image= and --
labels= command options.
Expand this hint for guidance on creating a pod that contains a label.
o Run the following command to create a pod named pod2:

kubectl run pod2 --image=redis --labels=tier=database

You can use labels to organize cluster resources by providing meaningful attributes for objects.
Labels do not affect the function of the resource.

 Display the status of pod1 and pod2 by using the kubectl get command.
If the kubectl get pods command returns a status of ContainerCreating for one of the pods, run the
command again. This status indicates that a pod is still in the creation stage.

If one or both of the pods fail, the cluster will not contain the configuration information necessary to
recreate the pod instances because they were created by using the imperative run command.

When you create objects by using a declarative object configuration, changes are retained.

Create a deployment by using an imperative command


Hints Enabled

No Yes
 Create an application deployment named apache that contains an httpd Docker image by using
the kubectl create command and the --image= option.
Expand this hint for guidance on creating a deployment.
o Run the following command to create a deployment named apache:

kubectl create deployment apache --image=httpd

A Kubernetes deployment is a logical object that defines a pod or multiple instances of the same
pod. You can use a deployment to scale the number of pods in the deployment, perform rolling pod
updates, and roll back version updates. In a production environment, it is considered a best practice
to create pods within in a deployment context and to avoid naked pod creation.

The create command is an imperative command that you can use to create a cluster object.

...less

 Display the pods that are running in the cluster by using the kubectl get command.
 Display the deployments that are running in the cluster by using the kubectl get command.

Expand this hint for guidance on displaying deployments.


o Run the following command to display the deployments:

kubectl get deployments

 Increase the number of apache deployment pods to 3 by using the kubectl scale command and
the --replicas= option.
Expand this hint for guidance on scaling a deployment.
o Run the following command to increase the number of pods running in the apache
deployment:

kubectl scale deployment --replicas=3 apache

The scale command is an imperative command that changes the number of pod replicas in a
deployment. You use the --replicas= option to specify the number of pod replicas.

A deployment creates a unique suffix that is appended to the pod name to distinguish identical pod
instances in the cluster.
...less
 Display the pods that are running in the cluster by using the kubectl get command.

Retrieve pod information

Hints Enabled

No Yes
 Retrieve information about the events in the event log by using the kubectl get command.
Expand this hint for guidance on retrieving event log information.
o Run the following command to retrieve event log information for a cluster:

kubectl get events

o The following screenshot shows the result of the kubectl get events command:

You can use events to retrieve high-level cluster event log information from the etcd cluster control
plane component. You can use events to review information about the creation of a pod.

 Retrieve detailed log information about pod2 by using the kubectl logs command.
Expand this hint for guidance on retrieving detailed log information about a pod.
o Run the following command to retrieve detailed log information about pod2:

kubectl logs pod2

 Display the status of the pod that contains the tier=database label by using the kubectl get
pods -l command.
Expand this hint for guidance on displaying the status of a pod that contains a label.
o Run the following command to display the status of a pod that contains a label:

kubectl get pods -l tier=database

You can use the -l option to filter objects by a key/value pair label.

 Determine the node on which the pods are running by using the kubectl get command and
the -o wide option.
Expand this hint for guidance on determining the node on which a pod is running.
o Run the following command to determine the node on which pod1 and pod2 are running:

kubectl get pods -o wide

o The following screenshot shows the result of the kubectl get pods -o wide command:

The -o wide (--output=wide) option displays detailed resource information. You can use this option
to determine the IP address and node names for a pod.

Pods may be assigned to run on any worker node depending on the resources available on each
node. The kube-scheduler cluster component that is running on the master node will assign the pod
to a node based on the resource knowledge it has for each node.

 Enter the IP address of pod1 in the IP Address text box.

IP Address

 Display the header information for the web server on pod1 by using the curl -I command and
the IP address NSXT.2-007: Configure Network Address Translation [Guided].

Expand this hint for guidance on verifying the functionality of a web server that is running on a pod.
o Run the following command to verify the functionality of the web server that is running on
pod1:

curl -I NSXT.2-007: Configure Network Address Translation [Guided]


o The following screenshot shows the result of the curl -I NSXT.2-007: Configure Network
Address Translation [Guided] command:

The -I curl option displays HTTP header information. You can use the curl command to verify that a
web server is answering HTTP requests. The status code 200 OK indicates that an HTTP request was
answered and the web server is functioning.

Delete a pod

Hints Enabled

No Yes
 Display the pods that are running in the cluster by using the kubectl get command.
 Delete the pod1 and pod2 by using the kubectl delete command.

Expand this hint for guidance on deleting a pod.


o Run the following commands to delete pod1 and pod2:

kubectl delete pod pod1

kubectl delete pod pod2

You can use the imperative delete command to delete a cluster object.

 Delete the apache deployment pods by using the kubectl delete command.
Expand this hint for guidance on deleting pods by deleting a deployment.
o Run the following commands to delete the apache deployment:

kubectl delete deployment apache

Deployment pods will be automatically recreated by the deployment if the pods are deleted or fail. A
deployment will always maintain the number of running pods that are specified in the deployment
configuration. To delete all of the pods that belong to a deployment, you must delete the
deployment.
 Display the pods that are running in the default namespace by using the kubectl get command.
You should see a message that there are no resources found in the default namespace.

You might also like