https://container.training/kube-selfpaced.yml.html#194
"However difficult life may seem, there is always something you can do and succeed at. It matters that you don't just give up." Stephen Hawking
- The Kubernetes API defines a lot of objects call resources
- We can see the full list by running
kubectl api-resources - We can view the definition of a field in a resource
kubectl explain node.spec kubectl describewill retrieve some extra information about the resource- We can see the components that make up the Kubernetes cluster
kubectl get componentstatuses
Declarative vs imperative
-
Declarative: I would like a cup of tea.
-
Imperative: Boil some water. Pour it in a teapot. Add tea leaves. Steep for a while. Serve in a cup.
$ kubectl get no -o json | jq ".items[] | {name:.metadata.name} + .status.capacity"
kubectl proxy &
By default:
- proxy binds: 127.0.0.1
- proxy listens: 8001
- accept connection from: ^localhost$,^127.0.0.1$,^[::1]$
Running kubectl proxy on a remote machine
kubectl proxy --port=8888 --address=0.0.0.0 --accept-hosts=.*
kubectl proxy also gives access to all internal services
We just add the URI to the end of the request, for instance:
curl localhost:8001/api/v1/namespaces/default/services/webui/proxy/index.html
if we want to access a TCP service we can use kubectl port-forward instead
kubectl port-forward svc/redis 10000:6379 &
- A service is a stable endpoint to connect to "something"
Viewing andpoint details
kubectl get endpoints
The Kubernetes API create a set of DNS records type "A"
kubectl expose deploy httpenv --port 8888 --cluster-ip=None
$ kubectl -n kube-public get pods
$ kubectl -n kube-public get configmaps
$ kubectl -n kube-public get configmap cluster-ingo -o yaml
$ curl -k https://10.96.0.1/api/v1/namespaces/kube-public/configmaps/cluster-info
$ curl -sk https://10.96.0.1/api/v1/namespaces/kube-public/configmaps/cluster-info | jq -r .data.kubeconfig
- flag
kubectl --kubeconfig .kube/config get po - env
KUBECONFIG=./kube/config kubectl get po - use path ``` $HOME/.kube/config
export KUBECONFIG=file1:file2
kubectl get pods --context=cluster-1
kubectl get pods --context=cluster-2
KUBECONFIG=file1:file2:file3 kubectl config view \
--merge --flatten > out.txt
KUBECONFIG=in.txt kubectl config view \
--minify --flatten --context=context-1 > out.txt
To update the server address, run:
kubectl config set-cluster kubernetes --server=https://X.X.X.X:6443
# Make sure to replace X.X.X.X with the IP address of node1!
KUBECONFIG= kubectl get nodes \
--server https://localhost:6443 \
--user docker-for-desktop \
--client-certificate my.cert \
--client-key my.key \
--insecure-skip-tls-verify
$ kubeon
{⎈ |N/A:N/A} $ export KUBECONFIG=f2
{⎈ |docker-for-desktop:default} $ export KUBECONFIG=f1
{⎈ |gke_ahmetb_us-central1-b_mycluster:kube-system} $ kubens default
Active namespace is "default".
{⎈ |gke_ahmetb_us-central1-b_mycluster:kube-system} $ kubeoff
$
Generate the kubeconfig file (replacing X.X.X.X with the address of kuberouter1):
kubectl config set-cluster cni --server http://X.X.X.X:8080
kubectl config set-context cni --cluster cni
kubectl config use-context cni
cp ~/.kube/config ~/kubeconfig
- Doesn't set up Docker or any other conrainer engine
- Doesn't set up the overlay network
- Doesn't set up multi-master ( no high avaliability )
This tutorial walks you through setting up Kubernetes the hard way. Kubernetes The Hard Way
kubectl run pingpong --image alpine ping 1.1.1.1
List most resource type: kubectl get all
-
A deployment is a high-level construct
- allows scaling, rolling updates, rollbacks
- multiple deployments can be used together to implement a canary deployment
- delegates pods management to replica sets
-
A replica set is a low-level construct
- makes sure that a given number of identical pods are running
- allows scaling
- rarely used directly
kubectl scale deploy/pingpong --replicas 3
or
kubectl scale deployment pingpong --replicas 3
Under the hood, kubectl run invokes "generator" to create resource descriptions
-
kubectl run --restart=OnFailure -
kubectl create <resource> -
kubectl create -f foo.yamlorkubectl apply -f foo.yaml
We can also create cronjobs
kubectl run --schedule=...
Stream the logs: kubectl logs -l run=pingpong --tail 1 -f
kubectl expose creates a service for existing pods
There are different types of services
ClusterIP,NodePort,LoadBalancer,ExternalName
kubectl get svc $SERVICE -o go-template={{ .spec.clusterIP }}
Dump the resource in YAML: kubectl get deploy/name -o yaml --export > name.yaml
Try to load our YAML file and ignore errors: kubectl apply -f name.yaml --validate=false
Show the rollout plan for our deployments:
kubectl get deploy -o json | jq ".items[] | {name:.metadata.name} + .spec.strategy.rollingUpdate"
Check the result kubectl config get-contexts
Update the current context kubectl config set-context --current --namespace=kube-system
Switch back to the original context kubectl config set-context --current --namespace=
https://github.com/ahmetb/kubectx
kube-ps1 makes it easy to track and highlighte part
https://github.com/jonmosco/kube-ps1
kubectl get sa default -o yaml
SECRET=$(kubectl get sa default -o json | jq -r .secrets[0].name)
Extracting the token
kubectl get secret
$ kubectl config set-credentials sa-user --token=$(kubectl get secret <secret_name> -o jsonpath={.data.token} | base64 -d)
Configuring the Kubernetes CLI by using service account tokens
- m5.4xlarge — monitoring Prometheus;
- c5.4xlarge — Node.js (однопоточная рабочая нагрузка);
- c5.2xlarge — Java и Go (многопоточная рабочая нагрузка);
- c5.4xlarge — для контрольной панели (3 узла).