Deployment on Kubernetes using Kubectl.
We can deploy containerized applications on that. To do that, we need to create Kubernetes Deployment. This deployment is responsible for the creating/ updating instance. Once deployment has been created, Kubernetes master will schedule the application instances that the deployment creates onto individual nodes in the cluster.
Once instance are created, Kubernetes Deployment controller will monitor the application instances continuously. If the instance down or deleted, Deployment monitor will replaces it. This is called self healing, which will help to address machine failure or maintenance.
In some other cloud technology, installation script will be used to start the applications. But, it will help on recovery from the system failure. In kubernetes will provide different approach by creating and running application instance on different nodes.
We can create and manage deployment by using Kubernetes Command line Interface (Kubectl). Kubectl will use kubernetes API to connect with cluster.
Kubectl basics:
Downloading Kubectl:
#wget https://storage.googleapis.com/kubernetes-release/release/v1.0.1/bin/linux/amd64/kubectl
Copying kubectl to path:
#chmod +x kubectl
#mv kubectl /usr/local/bin/
Downloading
client credentials and CA cert:
gcloud compute copy-files node0:~/admin-key.pem .
gcloud compute copy-files node0:~/admin.pem .
gcloud compute copy-files node0:~/ca.pem .
Getting Kubernetes controller external IP:
EXTERNAL_IP=$(gcloud compute ssh node0 --command
"curl -H 'Metadata-Flavor: Google'
http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip")
Creating cluster config:
kubectl config set-cluster workshop
--certificate-authority=ca.pem
--embed-certs=true
--server=https://${EXTERNAL_IP}:6443
Adding a admin credentials:
kubectl config set-credentials admin
--client-key=admin-key.pem
--client-certificate=admin.pem
--embed-certs=true
Configuring the cluster context:
kubectl config set-context workshop
--cluster=workshop
--user=admin
kubectl config use-context workshop
kubectl config view
Explore the kubectl CLI
Checking health status of the cluster components:
kubectl get cs
List pods:
kubectl get pods
List nodes:
kubectl get nodes
List services:
kubectl get services
"Kubectl run" command will create new deployment and have to provide deployment name,
application image location and port number.
Example:
#kubectl run kubernetes-bootcamp --image=docker.io/jocatalin/kubernetes-bootcamp:v1 --port=8080
command to display the deployment:
> kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILA
BLE AGE
kubernetes-bootcamp 1 1 1 1
2m
In default case deployed applications are visible inside of kubernetes cluster, before exposing.
To view the application without exposing outside, can add route between our
terminal and kubernetes cluster using proxy.
>kubectl proxy
Started proxy enables access to the API. The applications running inside the pod.
Get the pod name and store it in the POD_NAME environment variable.
>export POD_NAME=$(kubectl get pods -o go-template –template ‘{{range .items}}{{.metadata.name}}{{“n”}}{{end}}’) echo Name of the Pod: $POD_NAME
command to see application output:
>curl http://localhost:8001/api/v1/proxy/namespaces/default/pods/$POD_NAME/
Note: Will see more application related things in future post.