Skip to content

Instantly share code, notes, and snippets.

@bpineau
Created October 23, 2016 20:06
Show Gist options
  • Save bpineau/ebea8ce145dd3cda707ec88b007a41d9 to your computer and use it in GitHub Desktop.
Save bpineau/ebea8ce145dd3cda707ec88b007a41d9 to your computer and use it in GitHub Desktop.
# Un exemple de service+deployment/rc/rs tested-qui-marche, qui cree un ELB pour un service
# de type "LoadBalancer", et qui sait attacher tout seul un volume EBS.
# Teste sur un cluster AWS (2 nodes t2.micro) en kubernetes 1.3 cree avec kube-up.sh.
# kubectl create -f ce_fichier.yaml
# kubectl get pods -o wide # reperer le node hote
# se connecter au node, et faire
# echo plop >/var/lib/kubelet/plugins/kubernetes.io/aws-ebs/mounts/aws/eu-west-1a/vol-ba8fae39/index.html
# kubectl describe svc nginxsvc # reperer le nom du ELB, et faire un curl dessus
# kubectl get pods -o wide # reperer le nom du node
# kubectl drain ip-172-20-0-154.eu-west-1.compute.internal --force # shooter le node
# kubectl describe deployment aws-web # constater que le pod est re-schedulé, et repond au http
---
apiVersion: v1
kind: Service
metadata:
name: nginxsvc
labels:
app: nginx
spec:
# ceci cree un ELB automagiquement
type: LoadBalancer
#type: NodePort
ports:
- port: 80
protocol: TCP
name: http
selector:
app: nginx
---
# Si on veux que le pod soit re-schedule (et son volume re-attache/monte) en cas de panne d'un node,
# il faut un ReplicationController ou un ReplicationSet ou un Deployment (pas just un pod nu).
# "Deployment" est plus tendance que "ReplicationController" (mais encore "api beta" en 1.3)
apiVersion: v1
kind: Service
metadata:
name: nginxsvc
labels:
app: nginx
spec:
# ceci cree un ELB automagiquement
type: LoadBalancer
#type: NodePort
ports:
- port: 80
protocol: TCP
name: http
selector:
app: nginx
---
# Si on veux que le pod soit re-schedule (et son volume re-attache/monte) en cas de panne d'un node,
# il faut un ReplicationController ou un ReplicationSet ou un Deployment (pas just un pod nu).
# "Deployment" est plus tendance que "ReplicationController" (mais encore "api beta" en 1.3)
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: aws-web
spec:
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
volumeMounts:
- name: html-volume
mountPath: "/usr/share/nginx/html"
volumes:
- name: html-volume
awsElasticBlockStore:
# Enter the volume ID below (il faut creer l'EBS avant)
volumeID: aws://eu-west-1a/vol-ba8fae39
fsType: ext4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment