This includes how you can deploy a simple Docker image into a Minikube cluster which is nothing but a local K8s cluster. A K8s pod will be used as just a single K8s object to print "Hello World!" in this tutorial. Both imperative command and yaml resource definition will be included where "command" and "args" usage in K8s pod will be included. Busybox docker image will be used as the container image. Make sure to meet the mentioned prerequisites below.
Prerequisites.
1. Docker as the container runtime in your machine (see installation).
2. Minikube as the local Kubernetes cluster (see installation).
4. Make sure that your minikube cluster is started and running properly! You may use following commands to make sure this.
Check the status: `minikube status`
Start minikube: `minikube start`
Deployment using imperative command.
Imperative command mode provides the super fast deployment capability where we can meet our requirements by just a single command. All you need to do is that execute the following command.
kubectl run hello-world --image=busybox --restart=Never --command -- echo "Hello World!"
Explanation
kubectl logs -f hello-world
Deployment using YAML resource definition.
apiVersion: v1kind: Podmetadata:labels:run: hello-worldname: hello-worldspec:containers:- command:- echo- Hello World!image: busyboxname: hello-worldrestartPolicy: Never
Once the pod.yaml is ready with the above content, use the following command to deploy it in the cluster.
kubectl create -f pod.yaml
Use the following command again to check for pod logs.
kubectl logs -f hello-world
As per the pod.yaml definition above, the command itself has specified both the command and its arguments. Instead we can use args option to pass required arguments to the command which is specified in the command options. See the following YAML definition which includes the said change.
YAML name: pod-with-args.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
run: hello-world
name: hello-world
spec:
containers:
- command:
- echo
args
- Hello World!
image: busybox
name: hello-world
restartPolicy: Never
Once the pod-with-args.yaml is ready with above content, use the following command to deploy the pod.
kubectl create -f pod-with-args.yaml
Check pod logs using the following command once the pod is created.
kubectl logs -f hello-world
You can see Hello World! in your terminal as pod logs!
Post A Comment:
0 comments: