Skip to main content

Kubectl

Kubectl is Kubernetes command line interface

  • Kubectl uses the Kubernetes API to interact with the cluster
  • The common format of a kubectl command is: kubectl action resource
    • This performs the specified action (like createdescribe or delete) on the specified resource (like node or deployment). You can use --help after the subcommand to get additional info about possible parameters (for example: kubectl get nodes --help).

      Check that kubectl is configured to talk to your cluster, by running the kubectl version command.

      Check that kubectl is installed and you can see both the client and the server versions.

      To view the nodes in the cluster, run the kubectl get nodes command.

  • The most common operations can be done with the following kubectl subcommands:

    • kubectl get - list resources
    • kubectl describe - show detailed information about a resource
    • kubectl logs - print the logs from a container in a pod
    • kubectl exec - execute a command on a container in a pod

    You can use these commands to see when applications were deployed, what their current statuses are, where they are running and what their configurations are

  • Deploy an app using kubectl

    Let’s deploy our first app on Kubernetes with the kubectl create deployment command. We need to provide the deployment name and app image location (include the full repository url for images hosted outside Docker Hub).

    kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1

    Great! You just deployed your first application by creating a deployment. This performed a few things for you:

    • searched for a suitable node where an instance of the application could be run (we have only 1 available node)
    • scheduled the application to run on that Node
    • configured the cluster to reschedule the instance on a new Node when needed

    To list your deployments use the kubectl get deployments command

Comments

Popular posts from this blog

Networking in Kubernetes

Pods that are running inside Kubernetes are running on a private, isolated network. By default they are visible from other pods and services within the same Kubernetes cluster, but not outside that network Every Pod has a unique IP address And it is reachable from all other Pods in the K8s cluster A pod is a host, just like your laptop, having an ip-address and a range of ports that can be alloted to containers A container runs on a specific port inside a pod In a Kubernetes environment, when services are deployed within the same namespace , they can communicate with each other using the service name as the hostname e.g. in the following snippet from appsetting.json form a .net core project, ' document-api'  is the name of the service "DocumentApiConfiguration" : { "BaseUrl" : "http://document-api/" } What if I want to access a service from another namespace? When you want to access a service from another namespace in Kubernetes, you typica...

Terraform

It is an Infrastructure as Code tool Normally, if one has to configure VMs or other resources on the cloud, they have to go to the cloud provider's website and click a lot to get things done as supposed, terraform can do all of that provided you tell it precisely what to do in a .tf file e.g. which cloud provider you are using(GCP, Azure etc), which resource to configure with what specifications. One writes the file in hashicorp language (kinda like JSON) Free and Open source One has to install the CLI terraform init terraform apply  (to make the changes to cloud) terraform destroy

Kubernetes

Some keywords: Node A Node is a worker machine in Kubernetes and may be either a virtual or a physical machine, depending on the cluster Clusters Kubernetes coordinates a highly available cluster of computers (nodes) that are connected to work as a single unit Namespace Namespaces are a way to organize clusters into virtual sub-clusters — they can be helpful when different teams or projects share a Kubernetes cluster . Any number of namespaces are supported within a cluster , each logically separated from others but with the ability to communicate with each other Kubernetes: Kubernetes is a portable, extesible open-source platform for managing and orchestration containerized workloads . It abstracts away complex container management tasks Provides us with declarative configuration to orchestrate containers in different computing environments This orchestration platform gives you the same ease of use and flexibility you might already know from Platform-as-a-Service (PaaS) or Infrastruct...