Outils pour utilisateurs

Outils du site


systeme:kubernetes

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
Dernière révisionLes deux révisions suivantes
systeme:kubernetes [2016/11/12 12:04] – [kubectl create] rootsysteme:kubernetes [2021/07/01 22:17] – [Kubernetes] root
Ligne 2: Ligne 2:
   * [[http://kubernetes.io/|Site Officiel]]   * [[http://kubernetes.io/|Site Officiel]]
   * [[https://docs.kubernetic.com/|Autre doc]]   * [[https://docs.kubernetic.com/|Autre doc]]
 +  * [[https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/|Cheatsheet]]
   * [[systeme:docker|Docker]]   * [[systeme:docker|Docker]]
  
 +  * [[https://docs.helm.sh/using_helm/#installing-helm|Helm]]
 +
 +  * [[https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands|Toutes les commandes et options]]
 +
 +  * https://labs.play-with-docker.com
 +  * https://labs.play-with-k8s.com
 +===== Autres =====
 +  * [[http://kubernetes.io/docs/user-guide/ingress/|Ingress]]
 +  * [[http://kubernetes.io/docs/admin/daemons/|Daemons]]
 +  * [[http://kubernetes.io/docs/user-guide/images/|Images]]
 +  * [[http://kubernetes.io/docs/user-guide/jobs/|Jobs]]
 +  * [[http://kubernetes.io/docs/user-guide/scheduled-jobs/|Scheduled Jobs]]
 +  * [[http://kubernetes.io/docs/user-guide/labels/|Labels]]
 +  * [[http://kubernetes.io/docs/user-guide/namespaces/|Namespaces]]
 +  * [[http://kubernetes.io/docs/user-guide/networkpolicies/|Network Policies]]
 +  * [[http://kubernetes.io/docs/admin/node/|Node]]
 +  * [[http://kubernetes.io/docs/user-guide/persistent-volumes/|Persistent Volumes]]
 +  * [[http://kubernetes.io/docs/user-guide/volumes/|Volumes]]
 +  * [[http://kubernetes.io/docs/user-guide/ui/|Dashboard]]
 +  * [[http://kubernetes.io/docs/tasks/configure-pod-container/define-environment-variable-container/|Environnement dans un conteneur]]
 +  * [[http://kubernetes.io/docs/tasks/configure-pod-container/define-command-argument-container/|Commande dans un conteneur]]
 +  * [[http://kubernetes.io/docs/tasks/configure-pod-container/assign-cpu-ram-container/|Limiter les ressources pour un conteneur]]
 +  * [[http://kubernetes.io/docs/admin/resourcequota/|Quota sur les ressources 1]] + [[http://kubernetes.io/docs/admin/resourcequota/walkthrough/|Quota sur les ressources 2]]
 +  * [[http://kubernetes.io/docs/tasks/administer-cluster/assign-pods-nodes/|Assigner un pod à des nœuds]]
 +  * [[http://kubernetes.io/docs/user-guide/liveness/|POD health]]
 +  * [[http://kubernetes.io/docs/user-guide/monitoring/|Monitoring]]
 +  * [[http://kubernetes.io/docs/admin/cluster-components/|Composants Kubernetes]]
 +  * [[http://kubernetes.io/docs/admin/dns/|DNS]] + [[https://coreos.com/kubernetes/docs/latest/deploy-addons.html|kube-dns]]
 +
 +===== Affichage =====
 +Repérer le champ à afficher en yaml, puis isoler le pour l'afficher :
 +<xtermrtf>
 +$ kubectl get pod wordpress-2713623249-d46ky -o yaml
 +$ kubectl get -o template pod wordpress-2713623249-d46ky --template={{.status.podIP}}
 +</xtermrtf>
 ===== Commandes ===== ===== Commandes =====
 ==== kubectl ==== ==== kubectl ====
Ligne 9: Ligne 45:
  
 ==== kubectl annotate ==== ==== kubectl annotate ====
-[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_annotate/|Met une annotation sur un **pod** ou un **deployment**]] :+[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_annotate/|Met une annotation sur une ressource]] :
 <xtermrtf> <xtermrtf>
 # Update pod 'foo' with the annotation 'description' and the value 'my frontend'. # Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
Ligne 31: Ligne 67:
 $ kubectl annotate pods foo description- $ kubectl annotate pods foo description-
 </xtermrtf> </xtermrtf>
 +
 +<note>
 +  * http://kubernetes.io/docs/user-guide/annotations/
 +</note>
  
 ==== kubectl api-versions ==== ==== kubectl api-versions ====
Ligne 76: Ligne 116:
 $ kubectl autoscale rc foo --max=5 --cpu-percent=80 $ kubectl autoscale rc foo --max=5 --cpu-percent=80
 </xtermrtf> </xtermrtf>
 +
 +<note>
 +  * http://kubernetes.io/docs/user-guide/horizontal-pod-autoscaling/
 +</note>
  
 ==== kubectl cluster-info ==== ==== kubectl cluster-info ====
Ligne 143: Ligne 187:
 $ cat pod.json | kubectl create -f - $ cat pod.json | kubectl create -f -
 </xtermrtf> </xtermrtf>
 +
 +<note>
 +  * http://kubernetes.io/docs/user-guide/deployments/
 +</note>
  
 === kubectl create configmap === === kubectl create configmap ===
Ligne 257: Ligne 305:
 === kubectl create secret === === kubectl create secret ===
 [[http://kubernetes.io/docs/user-guide/kubectl/kubectl_create_secret/|Crée un secret]]. [[http://kubernetes.io/docs/user-guide/kubectl/kubectl_create_secret/|Crée un secret]].
 +
 +<note>
 +  * http://kubernetes.io/docs/user-guide/secrets/
 +</note>
  
 == kubectl create secret docker-registry == == kubectl create secret docker-registry ==
Ligne 325: Ligne 377:
 </xtermrtf> </xtermrtf>
  
 +==== kubectl drain ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_drain/|Bloque la création de nouveau pod puis supprime les pods du noeud]] :
 +<xtermrtf>
 +# Drain node "foo", even if there are pods not managed by a ReplicationController, ReplicaSet, Job, or DaemonSet on it.
 +$ kubectl drain foo --force
 +
 +# As above, but abort if there are pods not managed by a ReplicationController, ReplicaSet, Job, or DaemonSet, and use a grace period of 15 minutes.
 +$ kubectl drain foo --grace-period=900
 +</xtermrtf>
 +
 +==== kubectl edit ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_edit/|Edite la configuration d'une ressource]] :
 +<xtermrtf>
 +$ kubectl edit node k-node1
 +$ kubectl edit deployment nginx -o json
 +$ kubectl edit pod nginx-deployment-2644738339-826ks
 +$ kubectl edit svc/docker-registry --output-version=v1 -o json
 +</xtermrtf>
 +
 +==== kubectl exec ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_exec/|Execute une commande dans un conteneur]] :
 +<xtermrtf>
 +$ kubectl exec nginx-2644738339-826ks -it -- bash
 +$ kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il
 +</xtermrtf>
 +
 +==== kubectl explain ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_explain/|Documente une ressource]] :
 +<xtermrtf>
 +# Get the documentation of the resource and its fields
 +$ kubectl explain pods
 +
 +# Get the documentation of a specific field of a resource
 +$ kubectl explain pods.spec.containers
 +</xtermrtf>
 +
 +==== kubectl expose ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_expose/|Déclare une ressource comme un nouveau service]] :
 +<xtermrtf>
 +# Create a service for a replicated nginx, which serves on port 80 and connects to the containers on port 8000.
 +$ kubectl expose rc nginx --port=80 --target-port=8000
 +
 +# Create a service for a replication controller identified by type and name specified in "nginx-controller.yaml", which serves on port 80 and connects to the containers on port 8000.
 +$ kubectl expose -f nginx-controller.yaml --port=80 --target-port=8000
 +
 +# Create a service for a pod valid-pod, which serves on port 444 with the name "frontend"
 +$ kubectl expose pod valid-pod --port=444 --name=frontend
 +
 +# Create a second service based on the above service, exposing the container port 8443 as port 443 with the name "nginx-https"
 +$ kubectl expose service nginx --port=443 --target-port=8443 --name=nginx-https
 +
 +# Create a service for a replicated streaming application on port 4100 balancing UDP traffic and named 'video-stream'.
 +$ kubectl expose rc streamer --port=4100 --protocol=udp --name=video-stream
 +
 +# Create a service for a replicated nginx using replica set, which serves on port 80 and connects to the containers on port 8000.
 +$ kubectl expose rs nginx --port=80 --target-port=8000
 +
 +# Create a service for an nginx deployment, which serves on port 80 and connects to the containers on port 8000.
 +$ kubectl expose deployment nginx --port=80 --target-port=8000
 +</xtermrtf>
 +
 +<xtermrtf>
 +$ kubectl expose deployment my-nginx --port=80 --type=LoadBalancer
 +</xtermrtf>
 +
 +==== kubectl get ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_get/|Affiche une ressource]] :
 +<xtermrtf>
 +# List all pods in ps output format.
 +$ kubectl get pods
 +
 +# List all pods in ps output format with more information (such as node name).
 +$ kubectl get pods -o yaml
 +
 +# List a single replication controller with specified NAME in ps output format.
 +$ kubectl get replicationcontroller web
 +
 +# List a single pod in JSON output format.
 +$ kubectl get -o json pod web-pod-13je7
 +
 +# List a pod identified by type and name specified in "pod.yaml" in JSON output format.
 +$ kubectl get -f pod.yaml -o json
 +
 +# Return only the phase value of the specified pod.
 +$ kubectl get -o template pod/web-pod-13je7 --template=
 +
 +# List all replication controllers and services together in ps output format.
 +$ kubectl get rc,services
 +
 +# List one or more resources by their type and names.
 +$ kubectl get rc/web service/frontend pods/web-pod-13je7
 +</xtermrtf>
 +
 +==== kubectl label ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_label/|Gestion des labels sur les ressources]] :
 +<xtermrtf>
 +# Update pod 'foo' with the label 'unhealthy' and the value 'true'.
 +$ kubectl label pods foo unhealthy=true
 +
 +# Update pod 'foo' with the label 'status' and the value 'unhealthy', overwriting any existing value.
 +$ kubectl label --overwrite pods foo status=unhealthy
 +
 +# Update all pods in the namespace
 +$ kubectl label pods --all status=unhealthy
 +
 +# Update a pod identified by the type and name in "pod.json"
 +$ kubectl label -f pod.json status=unhealthy
 +
 +# Update pod 'foo' only if the resource is unchanged from version 1.
 +$ kubectl label pods foo status=unhealthy --resource-version=1
 +
 +# Update pod 'foo' by removing a label named 'bar' if it exists.
 +# Does not require the --overwrite flag.
 +$ kubectl label pods foo bar-
 +</xtermrtf>
 +
 +==== kubectl logs ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_logs/|Affiche les logs d'un conteneur dans un pod]] :
 +<xtermrtf>
 +# Return snapshot logs from pod nginx with only one container
 +$ kubectl logs nginx
 +
 +# Return snapshot of previous terminated ruby container logs from pod web-1
 +$ kubectl logs -p -c ruby web-1
 +
 +# Begin streaming the logs of the ruby container in pod web-1
 +$ kubectl logs -f -c ruby web-1
 +
 +# Display only the most recent 20 lines of output in pod nginx
 +$ kubectl logs --tail=20 nginx
 +
 +# Show all logs from pod nginx written in the last hour
 +$ kubectl logs --since=1h nginx
 +</xtermrtf>
 +
 +==== kubectl patch ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_patch/|Met un jour le champ d'une ressource]] :
 +<xtermrtf>
 +# Partially update a node using strategic merge patch
 +$ kubectl patch node k8s-node-1 -p '{"spec":{"unschedulable":true}}'
 +
 +# Partially update a node identified by the type and name specified in "node.json" using strategic merge patch
 +$ kubectl patch -f node.json -p '{"spec":{"unschedulable":true}}'
 +
 +# Update a container's image; spec.containers[*].name is required because it's a merge key
 +$ kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
 +
 +# Update a container's image using a json patch with positional arrays
 +$ kubectl patch pod valid-pod --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":"new image"}]
 +</xtermrtf>
 +
 +==== kubectl port-forward ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_port-forward/|Forward un port local vers un POD]] :
 +<xtermrtf>
 +# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
 +$ kubectl port-forward mypod 5000 6000
 +
 +# Listen on port 8888 locally, forwarding to 5000 in the pod
 +$ kubectl port-forward mypod 8888:5000
 +
 +# Listen on a random port locally, forwarding to 5000 in the pod
 +$ kubectl port-forward mypod :5000
 +
 +# Listen on a random port locally, forwarding to 5000 in the pod
 +$ kubectl port-forward  mypod 0:5000
 +</xtermrtf>
 +
 +==== kubectl proxy ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_proxy/|Met un proxy pour l'API kubernetes]] :
 +<xtermrtf>
 +# Listen on ports 5000 and 6000 locally, forwarding data to/from ports 5000 and 6000 in the pod
 +$ kubectl port-forward mypod 5000 6000
 +
 +# Listen on port 8888 locally, forwarding to 5000 in the pod
 +$ kubectl port-forward mypod 8888:5000
 +
 +# Listen on a random port locally, forwarding to 5000 in the pod
 +$ kubectl port-forward mypod :5000
 +
 +# Listen on a random port locally, forwarding to 5000 in the pod
 +$ kubectl port-forward  mypod 0:5000
 +</xtermrtf>
 +
 +==== kubectl replace ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_replace/|Remplace une ressource par une autre]] :
 +<xtermrtf>
 +# Replace a pod using the data in pod.json.
 +$ kubectl replace -f ./pod.json
 +
 +# Replace a pod based on the JSON passed into stdin.
 +$ cat pod.json | kubectl replace -f -
 +
 +# Update a single-container pod's image version (tag) to v4
 +$ kubectl get pod mypod -o yaml | sed 's/\(image: myimage\):.*$/\1:v4/' | kubectl replace -f -
 +
 +# Force replace, delete and then re-create the resource
 +$ kubectl replace --force -f ./pod.json
 +</xtermrtf>
 +
 +==== kubectl rolling-update ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_rolling-update/|Remplace un replication controller par un autre]] :
 +<xtermrtf>
 +# Update pods of frontend-v1 using new replication controller data in frontend-v2.json.
 +$ kubectl rolling-update frontend-v1 -f frontend-v2.json
 +
 +# Update pods of frontend-v1 using JSON data passed into stdin.
 +$ cat frontend-v2.json | kubectl rolling-update frontend-v1 -f -
 +
 +# Update the pods of frontend-v1 to frontend-v2 by just changing the image, and switching the
 +# name of the replication controller.
 +$ kubectl rolling-update frontend-v1 frontend-v2 --image=image:v2
 +
 +# Update the pods of frontend by just changing the image, and keeping the old name.
 +$ kubectl rolling-update frontend --image=image:v2
 +
 +# Abort and reverse an existing rollout in progress (from frontend-v1 to frontend-v2).
 +$ kubectl rolling-update frontend-v1 frontend-v2 --rollback
 +</xtermrtf>
 +
 +==== kubectl rollout ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_rollout/|Gére la pause, reprise ou retour arrière d'un déploiement]].
 +
 +=== kubectl rollout history ===
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_rollout_history/|Affiche l'historique des déploiements]] :
 +<xtermrtf>
 +# View the rollout history of a deployment
 +$ kubectl rollout history deployment/abc
 +
 +# View the details of deployment revision 3
 +$ kubectl rollout history deployment/abc --revision=3
 +</xtermrtf>
 +
 +=== kubectl rollout pause ===
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_rollout_pause/|Met le déploiement d'une ressource en pause]] :
 +<xtermrtf>
 +# Mark the nginx deployment as paused. Any current state of
 +# the deployment will continue its function, new updates to the deployment will not
 +# have an effect as long as the deployment is paused.
 +$ kubectl rollout pause deployment/nginx
 +</xtermrtf>
 +
 +=== kubectl rollout resume ===
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_rollout_resume/|Continue le déploiement d'une ressource qui était en pause]] :
 +<xtermrtf>
 +# Resume an already paused deployment
 +$ kubectl rollout resume deployment/nginx
 +</xtermrtf>
 +
 +=== kubectl rollout undo ===
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_rollout_undo/|Effectue un retour arrière sur un déploiement précédent]] :
 +<xtermrtf>
 +# Rollback to the previous deployment
 +$ kubectl rollout undo deployment/abc
 +
 +# Rollback to deployment revision 3
 +$ kubectl rollout undo deployment/abc --to-revision=3
 +</xtermrtf>
 +
 +==== kubectl run ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_run/|Démarre un conteneur à partir d'une image]] :
 +<xtermrtf>
 +# Start a single instance of nginx.
 +kubectl run nginx --image=nginx
 +
 +# Start a single instance of hazelcast and let the container expose port 5701 .
 +kubectl run hazelcast --image=hazelcast --port=5701
 +
 +# Start a single instance of hazelcast and set environment variables "DNS_DOMAIN=cluster" and "POD_NAMESPACE=default" in the container.
 +kubectl run hazelcast --image=hazelcast --env="DNS_DOMAIN=cluster" --env="POD_NAMESPACE=default"
 +
 +# Start a replicated instance of nginx.
 +kubectl run nginx --image=nginx --replicas=5
 +
 +# Dry run. Print the corresponding API objects without creating them.
 +kubectl run nginx --image=nginx --dry-run
 +
 +# Start a single instance of nginx, but overload the spec of the deployment with a partial set of values parsed from JSON.
 +kubectl run nginx --image=nginx --overrides='{ "apiVersion": "v1", "spec": { ... } }'
 +
 +# Start a pod of busybox and keep it in the foreground, don't restart it if it exits.
 +kubectl run -i -t busybox --image=busybox --restart=Never
 +
 +# Start the nginx container using the default command, but use custom arguments (arg1 .. argN) for that command.
 +kubectl run nginx --image=nginx -- <arg1> <arg2> ... <argN>
 +
 +# Start the nginx container using a different command and custom arguments.
 +kubectl run nginx --image=nginx --command -- <cmd> <arg1> ... <argN>
 +
 +# Start the perl container to compute π to 2000 places and print it out.
 +kubectl run pi --image=perl --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(2000)'
 +
 +# Start the scheduled job to compute π to 2000 places and print it out every 5 minutes.
 +kubectl run pi --schedule="0/5 * * * ?" --image=perl --restart=OnFailure -- perl -Mbignum=bpi -wle 'print bpi(2000)'
 +</xtermrtf>
 +
 +==== kubectl scale ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_scale/|Augmente ou réduite le nombre de conteneur pour un Deployment, ReplicaSet, Replication Controller, ou un Job]] :
 +<xtermrtf>
 +# Scale a replicaset named 'foo' to 3.
 +kubectl scale --replicas=3 rs/foo
 +
 +# Scale a resource identified by type and name specified in "foo.yaml" to 3.
 +kubectl scale --replicas=3 -f foo.yaml
 +
 +# If the deployment named mysql's current size is 2, scale mysql to 3.
 +kubectl scale --current-replicas=2 --replicas=3 deployment/mysql
 +
 +# Scale multiple replication controllers.
 +kubectl scale --replicas=5 rc/foo rc/bar rc/baz
 +
 +# Scale job named 'cron' to 3.
 +kubectl scale --replicas=3 job/cron
 +</xtermrtf>
 +
 +==== kubectl uncordon ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_uncordon/|Rend le nœud à nouveau éligible pour la création de PODs]] (voir [[#kubectl cordon]]):
 +<xtermrtf>
 +# Mark node "foo" as schedulable.
 +$ kubectl uncordon foo
 +</xtermrtf>
 +
 +==== kubectl version ====
 +[[http://kubernetes.io/docs/user-guide/kubectl/kubectl_version/|Affiche la version client/serveur]] :
 +<xtermrtf>
 +$ kubectl version
 +</xtermrtf>
systeme/kubernetes.txt · Dernière modification : 2021/07/01 22:19 de root