notes/software/Kubernetes.md

113 lines
4.6 KiB
Markdown
Raw Permalink Normal View History

2023-06-10 01:52:34 +00:00
# Vocabulary
https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/ - Good summary of the different parts
## Cluster
The largest unit, a kubernetes cluster is a collection of one or more worker machines (virtual or physical machines), and the control plane.
## Control plane
A control plane is in charge of managing worker nodes and pods in a cluster.
## Node
[A node](https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/) is a virtual or physical machine that in Kubernetes, and is managed by the control plane. A Node can have multiple pods, and the control plane is in charge of scheduling pods across nodes.
Each node runs at least:
- A Kubelet, the process responsible for handling communication between the control plane and the node. It manages the pods and containers running on a machine
- A [container runtime](https://kubernetes.io/docs/setup/production-environment/container-runtimes/) responsible for pulling the container image from a registry, unpacking the container, and running the application. Examples include containerd and docker.
## Deployment
A [deployment](https://kubernetes.io/docs/tutorials/kubernetes-basics/deploy-app/deploy-intro/) instructs kubernetes how to create and update instances of an application. It can be imagined similar to a blueprint. The term 'deployment' may also refer to the group of pods and replicas defined by one or more configuration files.
## Pod
A [pod](https://kubernetes.io/docs/tutorials/kubernetes-basics/explore/explore-intro/) is an abstraction that represents a group of one or more application containers, and shared resources. Some shared include storage and a private network. They are meant to represent a logical host, and a rough parallel might be a physical machine running a service, although this machine may have multiple network adapters. A deployment creates pods, and not containers.
## ReplicaSet
A [ReplicaSet](https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/), often referred to as a pod replica, is an identical copy of pod. They can be used for many things, most commonly high availability and load balancing.
## Service
A [service](https://kubernetes.io/docs/concepts/services-networking/service/) in Kubernetes is is an abstraction that defines a logical set of Pods and a policy to access them. A Service is defined using YAML or JSON, and is primarily used to expose a network application that's running on one or more Pods in a cluster. They also route traffic across a set of Pods, allowing Pods to die and replicate without impacting the application.
## `kubectl`
`kubectl` is the Kubernetes command line tool used to run commands against clusters. You can use `kubectl` to deploy applications, inspect and manage cluster resources, and view logs. The general format of the command follows `kubectl [action] [resource]`
## `minikube`
`minikube` creates a local Kubernetes cluster for development. It can be configured to deploy on bare metal, containers (like docker), or a VM (QEMU).
# Commands
## Common commands
- **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
## Start `minikube`
```
minikube start
```
## Stop `minikube`
```
minikube stop
```
## Expose services running in minikube
```
minikube services
```
## View the dashboard for `minikube`(run in new terminal window)
```
minikube dashboard
```
## Check that `kubectl` is configured to talk to the cluster
```
kubectl version
```
## View nodes in the server
```
kubectl get nodes
```
## List deployments
```
kubectl get deployments
```
## Start a proxy to access the private network
```
kubectl proxy
```
## Access the API of a pod (through the proxy)
```
curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/
```
Where `$POD_NAME` is the name of a pod, you can get this information with `kubectl get pods`
## Start a Bash session in a Pod's container
```
kubectl exec --ti $POD_NAME -- bash
```
## Create a new Service and expose it to external traffic
```
kubectl expose deployment/kubernetes-bootcamp --type="NodePort" --port 8080
```
## Apply a new label to pods
```
kubectl label pods "$POD_NAME" version=v1
```
## See if a Service is load-balancing traffic
```
kubectl describe services/$SERVICE_NAME
```
## Set a different desired amount of replicas for a deployment
```
kubectl scale deployments/$DEPLOYMENT_NAME --replicas=$DESIRED_NUM_OF_REPLICAS
```
# Tutorials
https://kubernetes.io/docs/tutorials/hello-minikube/
https://kubernetes.io/docs/tutorials/kubernetes-basics/