Skip to content

Instantly share code, notes, and snippets.

@remylavergne
Last active December 8, 2019 20:29
Show Gist options
  • Save remylavergne/4783ab55a182539afc0f82946baee675 to your computer and use it in GitHub Desktop.
Save remylavergne/4783ab55a182539afc0f82946baee675 to your computer and use it in GitHub Desktop.
[Rancher] Bind d'un dossier Pod vers le node Host #rancher #volume
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "8"
field.cattle.io/creatorId: user-8xxx7
field.cattle.io/publicEndpoints: '[{"addresses":["xxx.xxx.xxx.135"],"port":32754,"protocol":"TCP","serviceName":"default:nginx-volume-test-nodeport","allNodes":true}]'
creationTimestamp: "2019-12-08T14:27:49Z"
generation: 9
labels:
cattle.io/creator: norman
workload.user.cattle.io/workloadselector: deployment-yyyy-nginx-xxx-test # Mon namespace
name: nginx-volume-test
namespace: default
resourceVersion: "1573395"
selfLink: /apis/apps/v1/namespaces/default/deployments/nginx-volume-test
uid: 8a179f78-247a-4734-8b69-a0bb38312b26
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
workload.user.cattle.io/workloadselector: deployment-default-nginx-volume-test # Normalement nous sommes sur le bon node, vérifier quand même, sinon le path ne sera pas valide !
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
cattle.io/timestamp: "2019-12-08T14:52:54Z"
field.cattle.io/ports: '[[{"containerPort":80,"dnsName":"nginx-volume-test-nodeport","kind":"NodePort","name":"80tcp01","protocol":"TCP"}]]'
creationTimestamp: null
labels:
workload.user.cattle.io/workloadselector: deployment-default-nginx-volume-test
spec:
containers:
- image: nginx:latest
imagePullPolicy: Always
name: nginx-volume-test
ports:
- containerPort: 80
name: 80tcp01
protocol: TCP
resources: {}
securityContext:
allowPrivilegeEscalation: false
capabilities: {}
privileged: false
readOnlyRootFilesystem: false
runAsNonRoot: false
stdin: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
tty: true
volumeMounts:
- mountPath: /usr/share/nginx/html # Le path à monter / binder
name: mon_volume # Le nom de mon volume
dnsPolicy: ClusterFirst
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
volumes:
- hostPath:
path: /home/user/nginx-data # Le path sur le node / serveur Ubuntu
type: DirectoryOrCreate # Créer le fichier si inexistant
name: mon_volume # Le nom de mon volume
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2019-12-08T14:34:32Z"
lastUpdateTime: "2019-12-08T14:34:32Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2019-12-08T14:27:49Z"
lastUpdateTime: "2019-12-08T14:53:00Z"
message: ReplicaSet "nginx-volume-test-664fcd8cc5" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 9
readyReplicas: 1
replicas: 1
updatedReplicas: 1

[Rancher] Bind / Mount d'un dossier Pod / Container vers le node Host / serveur Ubuntu

Le but de cette manipulation est d'exposer vers le node host (ici une Ubuntu Server 18.06), un dossier du Pod / Container voulu. Cette méthode n'est pas optimale, et le mieux est de passer par un volume claim.

Exemple : Afficher un site statique via un container Nginx.

Avec Docker (compose) :

$ docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx

Avec Rancher:

  1. Déployement d'un workload :
  • Workload > Deploy
    • Name: nginx-test (Choisir le nom qui vous arrange)
    • Docker Image: nginx:latest
    • Namespace: Votre namespace actuel
    • Port Mapping > Add port
      • Publish the container port: 80
      • Protocol: TCP
      • As a > Node Port (Pour les tests : random)
    • Volumes > Add volume > Bind-mount directory from the node
      • Volume Name: mon_volume
      • Path on the Node: /home/user/nginx-data
      • The Path on the Node must be: A directory, or create if it does not exist
      • Mount Point: /usr/share/nginx/html (dossier par défaut de Nginx documentation)
  1. Launch pour créer le workload

  2. Tester si le container est bien déployé, vous devriez avoir le message de base de Nginx

  3. Créer un fichier html simple pour voir si la configuration fonctionne

Sur le serveur Ubuntu / le node, créer le fichier /home/user/nginx-data/index.html

<html>
  <p>Test de configuration</p>
</html>
  1. Rafraîchir la page du conteneur, et voir si notre nouvelle page html s'affiche.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment