Deploy an App
Deployments, Kubectl
Last updated
Deployments, Kubectl
Last updated
you can deploy your containerized applications on top of a running k8s cluster
to do so, you create a Kubernetes Deployment configuration that instructs Kubernetes how to create and update instances of your application
once you have a Deployment, the k8s master schedules application instances within the Deployment to run on individual Nodes in the cluster
Kubernetes Deployment Controller continuously monitors application instances once the application instances are created
if the Node hosting an instance goes down or is deleted, the Deployment controller replaces the instance with an instance on another Node in the cluster
this is a self-healing mechanism to address machine failure or maintenance
fundamentally different approach to application management than installation scripts that would be used to start applications but did not allow recovery from machine failure
Kubectl: the Kubernetes command line interface
you can create and manage Deployments using Kubectl
Kubectl uses the Kubernetes API to interact with the cluster
Applications need to be packaged into one of the supported container formats in order to be deployed on Kubernetes
when you create a Deployment, you'll need to specify:
the container image for your application
the number of replicas that you want to run
you can change this information later by updating your Deployment
a Pod is the basic execution unit of a Kubernetes application
each Pod is a part of a workload that is running on your cluster
common format of a kubectl command is kubectl {{ action }} {{ resource }}
performs the action on the resource
you can use --help
after the command to get additional info about possible parameters (e.g. kubectl get nodes -- help
)
kubectl version
- check that kubectl can talk to your cluster
kubectl get nodes
- view the nodes in the cluster
Kubernetes will choose where to deploy the app based on Node available resources
kubectl create deployment
- deploy app
you need to provide:
deployment name
app image location (include the full repository url for images hosted outside Docker hub)
creating this deployment did the following:
searched for a node where an instance of the application could be run
scheduled the application to run on that Node
configured the cluster to reschedule the instance on a new Node when needed
get deployments
- list your deployments
there is 1 deployment running a single instance of your app
instance is running inside a Docker container on your node
pods within Kubernetes are running on a private, isolated network
visible by other pods and services by default if they are within the same kubernetes cluster
not visible by other pods and services outside the network
kubectl allows us to interact through an API endpoint to communicate with our application
the kubectl
command creates a proxy that forwards communication into the cluster-wide, private network
you can terminate the proxy by using control + C
and it won't show any output while it is running
open a second terminal window to run the proxy
kubectl proxy
- run the proxy
proxy acts as a connection between the host (online terminal) and the Kubernetes cluster
proxy allows direct access to the API from the terminals
you can see all the APIs hosted through the proxy endpoint
curl http://localhost:8001/version
- query the version directly through the api using the curl
command
if port 8001 is not accessible, ensure that the kubectl proxy
is still running
the API server will automatically create an endpoint for each pod based on the pod name that is accessible through the proxy
export POD_NAME=$(kubectl get pods -o go-template --template '') echo Name of the Pod: $POD_NAME
- get the name of the pod and store it in the POD_NAME
environment variable
in order for the new deployment to be accessible without using the Proxy, a Service is required