Kubernetes - Kubectl

  • It is a command-line tool that allows you to run commands against Kubernetes clusters.

Deploying Images

  • To deploy an image to a Kubernetes cluster, use kubectl create deployment. (Since v1.18, kubectl run only creates a single bare Pod, not a Deployment, so nothing recreates it if it dies.)
kubectl create deployment <deployment-name> --image=<image-name>
 
# single Pod only (useful for quick tests)
kubectl run <pod-name> --image=<image-name>
  • Example:
kubectl create deployment synergychat-web --image=docker.io/bootdotdev/synergychat-web:latest

Get all Deployments

kubectl get deployments

Get all Pods

  • Pods are the smallest deployable units in Kubernetes.
  • A Pod represents a single instance of a running process in your cluster.
  • Pods contain one or more containers, such as Docker containers.
  • A pod is an abstraction over a container, and remember, a container is just a running instance of an image. To oversimplify, a pod is a running application.
kubectl get pods
  • To get wide output, you can use the -o wide flag.
kubectl get pods -o wide

Edit a Deployment

  • To edit a deployment, you can use the kubectl edit command.
kubectl edit deployment <deployment-name>

Delete a Deployment

  • To delete a deployment, you can use the kubectl delete command.
kubectl delete deployment <deployment-name>

Delete a Pod

  • To delete a pod, you can use the kubectl delete command.
kubectl delete pod <pod-name>

Get all ConfigMaps

  • ConfigMaps are a Kubernetes resource that allows you to store configuration data in key-value pairs.
  • ConfigMaps allow you to decouple your configurations from your container images.
kubectl get configmaps

Apply a ConfigMap

  • To apply a ConfigMap, you can use the kubectl apply command.
kubectl apply -f <configmap-file>

Get all Services

  • A Kubernetes Service is an abstraction which defines a logical set of Pods and a policy by which to access them.
  • Services enable a loose coupling between dependent Pods.
kubectl get services

Get all Nodes

  • A node is a worker machine in Kubernetes.
  • A node may be a VM or physical machine, depending on the cluster.
  • Each node has the services necessary to run pods and is managed by the control plane.
kubectl get nodes

Get all Namespaces

  • A namespace is a way to divide cluster resources between multiple users.
  • It is a way to divide cluster resources between multiple users.
kubectl get namespaces

Port Forwarding

  • To forward a port from a Kubernetes pod to your local machine, you can use the kubectl port-forward command.
kubectl port-forward <pod-name> <local-port>:<pod-port>

Proxy

  • To access the Kubernetes API server, you can use the kubectl proxy command.
kubectl proxy

Replica Sets

  • A ReplicaSet ensures that a specified number of pod replicas are running at any given time.
  • A ReplicaSet is defined with a spec that specifies how many replicas it should maintain.
kubectl get replicasets

Distributed Systems

Whenever you’re dealing with a system that involves multiple machines talking to each other over a network, you’re dealing with a distributed system. Distributed systems are inherently complex, and Kubernetes is no exception, but that complexity is generally abstracted away from you as a K8s user. That’s what makes Kubernetes so cool! It does a lot of the hard work for you.

  • A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another.
  • The components interact with one another in order to achieve a common goal.
  • Distributed systems are designed to improve performance and scalability.
  • They are also more fault-tolerant than centralized systems.
  • Distributed systems are used in many applications, such as cloud computing, big data processing, and social networks.
  • Examples of distributed systems include the Internet, Google’s search engine, and Amazon’s e-commerce platform.

Resource and Nodes

  • Resource: A resource is an object that Kubernetes manages. For example, a pod is a resource.
  • Node: A node is a worker machine in Kubernetes. It may be a VM or physical machine, depending on the cluster. Each node has the services necessary to run pods and is managed by the control plane.

Note: Kubernetes manages the resources that applications require and automatically distributes the load across nodes