# Deploy the first container$kubectlcreatedeploymentmultitool-ncodewizard--image=praqma/network-multitool
deployment.apps/multitoolcreated
kubectl create deployment actually creating a replica set for us.
We can verify it by running:
$ kubectl get all -n codewizard
## Expected output:
NAME READY UP-TO-DATE AVAILABLE
deployment.apps/multitool 1/1 1 1
NAME DESIRED CURRENT READY
replicaset.apps/multitool-7885b5f94f 1 1 1
NAME READY STATUS RESTARTS
pod/multitool-7885b5f94f-9s7xh 1/1 Running 0
The above deployment contains a container named, multitool.
In order for us to be able to access this multitool container, we need to create a resource of type Service which will “open” the server for incoming traffic.
# "Expose" the desired port for incoming traffic# This command is equivalent to declare a `kind: Service` im YAML file$kubectlexposedeployment-ncodewizardmultitool--port80--typeNodePort
service/multitoolexposed
Verify that the service have been created by running:
$kubectlgetservice-ncodewizard
# The output should be something likeNAMETYPECLUSTER-IPEXTERNAL-IPPORT(S)AGE
service/multitoolNodePort10.102.73.248<none>80:31418/TCP3s
Find the port & the IP which was assigned to our pod by the cluster.¶
Grab the port from the previous output.
Port: In the above sample its 31418 [80:31418/TCP]
IP: we will need to grab the cluster ip using kubectl cluster-info
# get the IP$kubectlcluster-info
# You should get output similar to this oneKubernetescontrolplaneisrunningathttps://192.168.49.2:8443
KubeDNSisrunningathttps://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
# Programmatically get the port and the IPCLUSTER_IP=$(kubectlgetnodes\--selector=node-role.kubernetes.io/control-plane\-ojsonpath='{$.items[*].status.addresses[?(@.type=="InternalIP")].address}')NODE_PORT=$(kubectlget-o\jsonpath="{.spec.ports[0].nodePort}"\servicesmultitool-ncodewizard)
Test to see if the deployment worked using the ip address and port number we have retrieved above.
Execute curl with the following parameters: http://${CLUSTER_IP}:${NODE_PORT}
curlhttp://${CLUSTER_IP}:${NODE_PORT}# Or in the above samplecurl192.168.49.2:30436
# The output should be similar to this:PraqmaNetworkMultiTool(withNGINX)...
- If you get the above output, congratulations! You have successfully created a deployment using imperative commands.