systeme:kubernetes
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédenteDernière révisionLes deux révisions suivantes | ||
systeme:kubernetes [2016/11/12 12:04] – [kubectl create] root | systeme:kubernetes [2021/07/01 22:17] – [Kubernetes] root | ||
---|---|---|---|
Ligne 2: | Ligne 2: | ||
* [[http:// | * [[http:// | ||
* [[https:// | * [[https:// | ||
+ | * [[https:// | ||
* [[systeme: | * [[systeme: | ||
+ | * [[https:// | ||
+ | |||
+ | * [[https:// | ||
+ | |||
+ | * https:// | ||
+ | * https:// | ||
+ | ===== Autres ===== | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | ===== Affichage ===== | ||
+ | Repérer le champ à afficher en yaml, puis isoler le pour l' | ||
+ | < | ||
+ | $ kubectl get pod wordpress-2713623249-d46ky -o yaml | ||
+ | $ kubectl get -o template pod wordpress-2713623249-d46ky --template={{.status.podIP}} | ||
+ | </ | ||
===== Commandes ===== | ===== Commandes ===== | ||
==== kubectl ==== | ==== kubectl ==== | ||
Ligne 9: | Ligne 45: | ||
==== kubectl annotate ==== | ==== kubectl annotate ==== | ||
- | [[http:// | + | [[http:// |
< | < | ||
# Update pod ' | # Update pod ' | ||
Ligne 31: | Ligne 67: | ||
$ kubectl annotate pods foo description- | $ kubectl annotate pods foo description- | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | * http:// | ||
+ | </ | ||
==== 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 | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | * http:// | ||
+ | </ | ||
==== kubectl cluster-info ==== | ==== kubectl cluster-info ==== | ||
Ligne 143: | Ligne 187: | ||
$ cat pod.json | kubectl create -f - | $ cat pod.json | kubectl create -f - | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | * http:// | ||
+ | </ | ||
=== kubectl create configmap === | === kubectl create configmap === | ||
Ligne 257: | Ligne 305: | ||
=== kubectl create secret === | === kubectl create secret === | ||
[[http:// | [[http:// | ||
+ | |||
+ | < | ||
+ | * http:// | ||
+ | </ | ||
== kubectl create secret docker-registry == | == kubectl create secret docker-registry == | ||
Ligne 325: | Ligne 377: | ||
</ | </ | ||
+ | ==== kubectl drain ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # Drain node " | ||
+ | $ kubectl drain foo --force | ||
+ | |||
+ | # As above, but abort if there are pods not managed by a ReplicationController, | ||
+ | $ kubectl drain foo --grace-period=900 | ||
+ | </ | ||
+ | |||
+ | ==== kubectl edit ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | $ kubectl edit node k-node1 | ||
+ | $ kubectl edit deployment nginx -o json | ||
+ | $ kubectl edit pod nginx-deployment-2644738339-826ks | ||
+ | $ kubectl edit svc/ | ||
+ | </ | ||
+ | |||
+ | ==== kubectl exec ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | $ kubectl exec nginx-2644738339-826ks -it -- bash | ||
+ | $ kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il | ||
+ | </ | ||
+ | |||
+ | ==== kubectl explain ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 | ||
+ | </ | ||
+ | |||
+ | ==== kubectl expose ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 " | ||
+ | $ 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 " | ||
+ | $ 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 " | ||
+ | $ 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 ' | ||
+ | $ 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 | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | $ kubectl expose deployment my-nginx --port=80 --type=LoadBalancer | ||
+ | </ | ||
+ | |||
+ | ==== kubectl get ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 " | ||
+ | $ kubectl get -f pod.yaml -o json | ||
+ | |||
+ | # Return only the phase value of the specified pod. | ||
+ | $ kubectl get -o template pod/ | ||
+ | |||
+ | # 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/ | ||
+ | </ | ||
+ | |||
+ | ==== kubectl label ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # Update pod ' | ||
+ | $ kubectl label pods foo unhealthy=true | ||
+ | |||
+ | # Update pod ' | ||
+ | $ 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 " | ||
+ | $ kubectl label -f pod.json status=unhealthy | ||
+ | |||
+ | # Update pod ' | ||
+ | $ kubectl label pods foo status=unhealthy --resource-version=1 | ||
+ | |||
+ | # Update pod ' | ||
+ | # Does not require the --overwrite flag. | ||
+ | $ kubectl label pods foo bar- | ||
+ | </ | ||
+ | |||
+ | ==== kubectl logs ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 | ||
+ | </ | ||
+ | |||
+ | ==== kubectl patch ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # Partially update a node using strategic merge patch | ||
+ | $ kubectl patch node k8s-node-1 -p ' | ||
+ | |||
+ | # Partially update a node identified by the type and name specified in " | ||
+ | $ kubectl patch -f node.json -p ' | ||
+ | |||
+ | # Update a container' | ||
+ | $ kubectl patch pod valid-pod -p ' | ||
+ | |||
+ | # Update a container' | ||
+ | $ kubectl patch pod valid-pod --type=' | ||
+ | </ | ||
+ | |||
+ | ==== kubectl port-forward ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 | ||
+ | </ | ||
+ | |||
+ | ==== kubectl proxy ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 | ||
+ | </ | ||
+ | |||
+ | ==== kubectl replace ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 ' | ||
+ | |||
+ | # Force replace, delete and then re-create the resource | ||
+ | $ kubectl replace --force -f ./pod.json | ||
+ | </ | ||
+ | |||
+ | ==== kubectl rolling-update ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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: | ||
+ | |||
+ | # Update the pods of frontend by just changing the image, and keeping the old name. | ||
+ | $ kubectl rolling-update frontend --image=image: | ||
+ | |||
+ | # Abort and reverse an existing rollout in progress (from frontend-v1 to frontend-v2). | ||
+ | $ kubectl rolling-update frontend-v1 frontend-v2 --rollback | ||
+ | </ | ||
+ | |||
+ | ==== kubectl rollout ==== | ||
+ | [[http:// | ||
+ | |||
+ | === kubectl rollout history === | ||
+ | [[http:// | ||
+ | < | ||
+ | # View the rollout history of a deployment | ||
+ | $ kubectl rollout history deployment/ | ||
+ | |||
+ | # View the details of deployment revision 3 | ||
+ | $ kubectl rollout history deployment/ | ||
+ | </ | ||
+ | |||
+ | === kubectl rollout pause === | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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/ | ||
+ | </ | ||
+ | |||
+ | === kubectl rollout resume === | ||
+ | [[http:// | ||
+ | < | ||
+ | # Resume an already paused deployment | ||
+ | $ kubectl rollout resume deployment/ | ||
+ | </ | ||
+ | |||
+ | === kubectl rollout undo === | ||
+ | [[http:// | ||
+ | < | ||
+ | # Rollback to the previous deployment | ||
+ | $ kubectl rollout undo deployment/ | ||
+ | |||
+ | # Rollback to deployment revision 3 | ||
+ | $ kubectl rollout undo deployment/ | ||
+ | </ | ||
+ | |||
+ | ==== kubectl run ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # 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 " | ||
+ | kubectl run hazelcast --image=hazelcast --env=" | ||
+ | |||
+ | # 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=' | ||
+ | |||
+ | # 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 -- < | ||
+ | |||
+ | # Start the nginx container using a different command and custom arguments. | ||
+ | kubectl run nginx --image=nginx --command -- <cmd> < | ||
+ | |||
+ | # 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=" | ||
+ | </ | ||
+ | |||
+ | ==== kubectl scale ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # Scale a replicaset named ' | ||
+ | kubectl scale --replicas=3 rs/foo | ||
+ | |||
+ | # Scale a resource identified by type and name specified in " | ||
+ | kubectl scale --replicas=3 -f foo.yaml | ||
+ | |||
+ | # If the deployment named mysql' | ||
+ | kubectl scale --current-replicas=2 --replicas=3 deployment/ | ||
+ | |||
+ | # Scale multiple replication controllers. | ||
+ | kubectl scale --replicas=5 rc/foo rc/bar rc/baz | ||
+ | |||
+ | # Scale job named ' | ||
+ | kubectl scale --replicas=3 job/cron | ||
+ | </ | ||
+ | |||
+ | ==== kubectl uncordon ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | # Mark node " | ||
+ | $ kubectl uncordon foo | ||
+ | </ | ||
+ | |||
+ | ==== kubectl version ==== | ||
+ | [[http:// | ||
+ | < | ||
+ | $ kubectl version | ||
+ | </ |
systeme/kubernetes.txt · Dernière modification : 2021/07/01 22:19 de root