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 runonly 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:latestGet all Deployments
kubectl get deploymentsGet 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 wideflag.
kubectl get pods -o wideEdit a Deployment
- To edit a deployment, you can use the
kubectl editcommand.
kubectl edit deployment <deployment-name>Delete a Deployment
- To delete a deployment, you can use the
kubectl deletecommand.
kubectl delete deployment <deployment-name>Delete a Pod
- To delete a pod, you can use the
kubectl deletecommand.
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 configmapsApply a ConfigMap
- To apply a ConfigMap, you can use the
kubectl applycommand.
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 servicesGet 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 nodesGet 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 namespacesPort Forwarding
- To forward a port from a Kubernetes pod to your local machine, you can use the
kubectl port-forwardcommand.
kubectl port-forward <pod-name> <local-port>:<pod-port>Proxy
- To access the Kubernetes API server, you can use the
kubectl proxycommand.
kubectl proxyReplica Sets
- A ReplicaSet ensures that a specified number of pod replicas are running at any given time.
- A ReplicaSet is defined with a
specthat specifies how many replicas it should maintain.
kubectl get replicasetsDistributed 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.