Outils pour utilisateurs

Outils du site


systeme:kubernetes

Ceci est une ancienne révision du document !


Kubernetes

Commandes

kubectl

kubectl annotate

Met une annotation sur un **pod** ou un **deployment** :

# Update pod 'foo' with the annotation 'description' and the value 'my frontend'.
# If the same annotation is set multiple times, only the last value will be applied
$ kubectl annotate pods foo description='my frontend'

# Update a pod identified by type and name in "pod.json"
$ kubectl annotate -f pod.json description='my frontend'

# Update pod 'foo' with the annotation 'description' and the value 'my frontend running nginx', overwriting any existing value.
$ kubectl annotate --overwrite pods foo description='my frontend running nginx'

# Update all pods in the namespace
$ kubectl annotate pods --all description='my frontend running nginx'

# Update pod 'foo' only if the resource is unchanged from version 1.
$ kubectl annotate pods foo description='my frontend running nginx' --resource-version=1

# Update pod 'foo' by removing an annotation named 'description' if it exists.
# Does not require the --overwrite flag.
$ kubectl annotate pods foo description-

kubectl api-versions

Affiche les différentes API :

kubectl api-versions
autoscaling/v1
batch/v1
extensions/v1beta1
v1

kubectl apply

Applique les changements sur les pods :

$ kubectl apply -f ./myapp.yaml

On peut prendre en compte également tous les fichiers d'un répertoire de façon récursive :

$ kubectl apply -R -f ./directory

kubectl attach

S'attacher à un conteneur qui est démarré :

# Get output from running pod 123456-7890, using the first container by default
$ kubectl attach 123456-7890

# Get output from ruby-container from pod 123456-7890
$ kubectl attach 123456-7890 -c ruby-container

# Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod 123456-7890
# and sends stdout/stderr from 'bash' back to the client
$ kubectl attach 123456-7890 -c ruby-container -i -t

kubectl autoscale

Auto-scale un Deployment, ReplicaSet, ou ReplicationController :

# Auto scale a deployment "foo", with the number of pods between 2 and 10, target CPU utilization specified so a default autoscaling policy will be used:
$ kubectl autoscale deployment foo --min=2 --max=10

# Auto scale a replication controller "foo", with the number of pods between 1 and 5, target CPU utilization at 80%:
$ kubectl autoscale rc foo --max=5 --cpu-percent=80

kubectl cluster-info

Affiche les informations du cluster :

$ kubectl cluster-info

kubectl config

kubectl config current-context

kubectl config set-cluster

kubectl config set-context

kubectl config set-credentials

kubectl config set

kubectl config unset

kubectl config use-context

kubectl config view

kubectl convert

Convertit des fichiers entre différentes versions d'API :

# Convert 'pod.yaml' to latest version and print to stdout.
$ kubectl convert -f pod.yaml

# Convert the live state of the resource specified by 'pod.yaml' to the latest version
# and print to stdout in json format.
$ kubectl convert -f pod.yaml --local -o json

# Convert all files under current directory to latest version and create them all.
$ kubectl convert -f . | kubectl create -f -

kubectl cordon

kubectl create

Crée un nouvelle ressource :

# Create a pod using the data in pod.json.
$ kubectl create -f ./pod.json

# Recursive mode
$ kubectl create -R -f ./mydirectory

# Create a pod based on the JSON passed into stdin.
$ cat pod.json | kubectl create -f -

kubectl create configmap

Crée une entrée configmap :

# Create a new configmap named my-config with keys for each file in folder bar
$ kubectl create configmap my-config --from-file=path/to/bar

# Create a new configmap named my-config with specified keys instead of names on disk
$ kubectl create configmap my-config --from-file=key1=/path/to/bar/file1.txt --from-file=key2=/path/to/bar/file2.txt

# Create a new configmap named my-config with key1=config1 and key2=config2
$ kubectl create configmap my-config --from-literal=key1=config1 --from-literal=key2=config2

Modifier une config map :

$ kubectl create configmap nginx-lb-config --from-file=nginx-lb.configmap --dry-run -o yaml | kubectl replace configmap nginx-lb-config -f -

Exemple de configmap :

apiVersion: v1
kind: ConfigMap
metadata:
 Name: example-configmap
data:
 # property-like keys
 game-properties-file-name: game.properties
 ui-properties-file-name: ui.properties
 # file-like keys
 game.properties: |
   enemies=aliens
   lives=3
   enemies.cheat=true
   enemies.cheat.level=noGoodRotten
   secret.code.passphrase=UUDDLRLRBABAS
   secret.code.allowed=true
   secret.code.lives=30
 ui.properties: |
   color.good=purple
   color.bad=yellow
   allow.textmode=true
   how.nice.to.look=fairlyNice

Exemple de création qui utilisera le configmap définit au-dessus :

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
 name: configmap-example-deployment
 labels:
   name: configmap-example-deployment
spec:
 replicas: 1
 selector:
   matchLabels:
     name: configmap-example
 template:
   metadata:
     labels:
       name: configmap-example
   spec:
     containers:
     - name: game-container
       image: imaginarygame
       command: [ "game-server", "--config-dir=/etc/game/cfg" ]
       env:
       # consume the property-like keys in environment variables
       - name: GAME_PROPERTIES_NAME
         valueFrom:
           configMapKeyRef:
             name: example-configmap
             key: game-properties-file-name
       - name: UI_PROPERTIES_NAME
         valueFrom:
           configMapKeyRef:
             name: example-configmap
             key: ui-properties-file-name
       volumeMounts:
       - name: config-volume
         mountPath: /etc/game
     volumes:
     # consume the file-like keys of the configmap via volume plugin
     - name: config-volume
       configMap:
         name: example-configmap
         items:
         - key: ui.properties
           path: cfg/ui.properties
        - key: game.properties
          path: cfg/game.properties
     restartPolicy: Never 

kubectl create namespace

Crée un namespace avec un nom spécifique :

$ kubectl create namespace my-namespace

kubectl create serviceaccount

kubectl create secret

kubectl create secret docker-registry

Crée un secret pour un registry docker :

$ kubectl create secret docker-registry my-secret --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL

kubectl create secret generic

Crée un secret à partir d'un dossier, fichier ou valeur :

# Create a new secret named my-secret with keys for each file in folder bar
$ kubectl create secret generic my-secret --from-file=path/to/bar

# Create a new secret named my-secret with specified keys instead of names on disk
$ kubectl create secret generic my-secret --from-file=ssh-privatekey=~/.ssh/id_rsa --from-file=ssh-publickey=~/.ssh/id_rsa.pub

# Create a new secret named my-secret with key1=supersecret and key2=topsecret
$ kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret

kubectl delete

Supprime une ressource :

# Delete a pod using the type and name specified in pod.json.
$ kubectl delete -f ./pod.json

# Delete a pod based on the type and name in the JSON passed into stdin.
$ cat pod.json | kubectl delete -f -

# Delete pods and services with same names "baz" and "foo"
$ kubectl delete pod,service baz foo

# Delete pods and services with label name=myLabel.
$ kubectl delete pods,services -l name=myLabel

# Delete a pod immediately (no graceful shutdown)
$ kubectl delete pod foo --now

# Delete a pod with UID 1234-56-7890-234234-456456.
$ kubectl delete pod 1234-56-7890-234234-456456

# Delete all pods
$ kubectl delete pods --all

kubectl describe

Décrit une ressource :

# Describe a node
$ kubectl describe nodes kubernetes-minion-emt8.c.myproject.internal

# Describe a pod
$ kubectl describe pods/nginx

# Describe a pod identified by type and name in "pod.json"
$ kubectl describe -f pod.json

# Describe all pods
$ kubectl describe pods

# Describe pods by label name=myLabel
$ kubectl describe po -l name=myLabel

# Describe all pods managed by the 'frontend' replication controller (rc-created pods
# get the name of the rc as a prefix in the pod the name).
$ kubectl describe pods frontend

systeme/kubernetes.1478952243.txt.gz · Dernière modification : 2016/11/12 12:04 de root