from dev to devops · from dev to devops: an unexpected journey luis angel vicente sanchez...
TRANSCRIPT
From Dev to DevOps:
An Unexpected Journey
Luis Angel Vicente Sanchez
BigCentech Ltd
What is DevOps?
3
By Devops.png: Rajiv.Pantderivative work: Wylve - This file was derived from Devops.png:, CC BY 3.0, https://commons.wikimedia.org/w/index.php?curid=20202905
Who am I?
7
12+ Software Engineer
Big fan of functional programming
Lately a lot of Big DataLuis Angel Vicente Sanchez
http://bigcente.ch
Deploying to AWS: Terraform modules
16
https://github.com/heartysoft/cassy-up/tree/master/terraform/dse-cassandra
https://github.com/heartysoft/cassy-up/tree/master/terraform/kafka
Deploying to AWS: EC2 instances
17
resource "aws_instance" "dse-cassandra" {
count = "${var.count}"
ami = "${var.ami_id}"
key_name = "datalake"
instance_type = "${var.instance_type}"
availability_zone = "${var.availability_zones[...]}"
subnet_id = "${var.subnet_ids[var.availability_zones[...]]}"
vpc_security_group_ids = [ "${var.sg_ids}" ]
tags = {
Name = "${format("%s-%d", var.tag_name, count.index + 1)}"
}
}
Deploying to AWS: EBS volumes
18
resource "aws_ebs_volume" "dse-cassandra-ebs-data" {
count = "${var.count}"
availability_zone = "${var.availability_zones[...]}"
size = "${var.data_ebs_size}"
type = "${var.data_ebs_type}"
tags {
Name = "${var.tag_name} - Data Vol"
}
}
Deploying to AWS: EBS attachments
19
resource "aws_volume_attachment" "dse-cassandra-ebs-data-attach" {
count = "${var.count}"
device_name = "/dev/xvdh"
volume_id = "${aws_ebs_volume.dse-cassandra-ebs-data.*.id[count.index]}"
instance_id = "${aws_instance.dse-cassandra.*.id[count.index]}"
force_detach = true
}
Deploying to AWS: Provisioning
20
resource "null_resource" "provision-dse-cassandra" {
...
connection {
user = "${var.ssh_user}"
host = "${element(aws_instance.dse-cassandra.*.private_ip, count.index)}"
agent = true
private_key = "${file("${var.ssh_identity_file}")}"
}
...
}
Deploying to AWS: Provisioning
21
resource "null_resource" "provision-dse-cassandra" {
...
provisioner "file" {
source = "${var.provisioning_scripts}/dse-cassandra"
destination = "/tmp/cassy-up"
}
provisioner "file" {
source = "${var.provisioning_scripts}/environments/aws/dse_cassandra.sh"
destination = "/tmp/cassy-up/dse_cassandra.sh"
}
...
}
Deploying to AWS: Provisioning
22
resource "null_resource" "provision-dse-cassandra" {
...
provisioner "remote-exec" {
inline = [
"echo 'export CASSANDRA_CLUSTER_NAME=${var.cluster_name}' ...",
...
"chmod -R a+x /tmp/cassy-up/*",
"sudo /tmp/cassy-up/dse_cassandra.sh"
]
}
}
Kubernetes: Why?
24
Self-healing
Service
Discovery
Horizontal
Scaling
Rolling
upgrades
and
rollbacks
Kubernetes: Resize the cluster
26
┌[luis@BigCentech-Precision5520]-(~)
└> kops create cluster --zones eu-west-1a,eu-west-1b,eu-west-1c $CLUSTERNAME
┌[luis@BigCentech-Precision5520]-(~)
└> kops edit cluster $CLUSTERNAME
┌[luis@BigCentech-Precision5520]-(~)
└> kops update cluster $CLUSTERNAME --yes
┌[luis@BigCentech-Precision5520]-(~)
└> kops export kubecfg $CLUSTERNAME
Kubernetes: Resize the cluster
27
┌[luis@BigCentech-Precision5520]-(~)
└> kops edit ig nodes
┌[luis@BigCentech-Precision5520]-(~)
└> export KOPS_FEATURE_FLAGS="+DrainAndValidateRollingUpdate"
┌[luis@BigCentech-Precision5520]-(~)
└> kops rolling-update cluster --yes
Kubernetes: What is a Pod?
29
kubectl create -f
mypod.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Kubernetes: What is a Service?
30
kubectl create -f
myservice.yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-service
labels:
app: nginx
spec:
ports:
- port: 80
targetPort: 80
selector:
app: nginx
Kubernetes: What is a Deployment?
31
kubectl create -f
mydeployment.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
Kubernetes: Problems?
37
HEAPSTER INFLUXDB
Node 0
Pod 1
Pod 0
Node 1
Pod 3
Pod 2
Node 3
Pod 5
Pod 4
GRAFANA
Kubernetes: Problems?
38
TELEGRAF INFLUXDB
Node 0
Pod 1
Pod 0
Node 1
Pod 3
Pod 2
Node 3
Pod 5
Pod 4
GRAFANA
Deployment Pipeline: Stages
42
Build
(on commit)
Test
(on commit)
Deploy
(on tag)Publish ContainerBuild Test Deploy
Deployment Pipeline: Jobs
44
build:
stage: build
script:
- npm install
- npm run build
publish-container:
stage: publish-container
image: heartysoft/docker-builder-aws:0.15.0
script:
- chmod +x ./ci/*
- ./ci/publish-container.sh "app-ui" "$CI_COMMIT_TAG" "app/app-ui"
only:
- tags
Deployment Pipeline
45
Publish Container
(on tag)
Build
(on commit)
Test
(on commit)
Deploy
(on tag)
Publish Container
(on tag)
Build
(on commit)
Test
(on commit)
Deploy
(on tag)
Deployment Pipeline: Helm Chart
49
└── mychart
├── charts
├── Chart.yaml
├── templates
│ ├── deployment.yaml
│ ├── _helpers.tpl
│ ├── ingress.yaml
│ ├── NOTES.txt
│ └── service.yaml
└── values.yaml
Deployment Pipeline: Chart.yaml
50
apiVersion: v1
description: A Helm chart for Kubernetes
name: mychart
version: 0.1.0
Deployment Pipeline: values.yaml
51
replicaCount: 1
image:
repository: nginx
tag: stable
pullPolicy: IfNotPresent
service:
name: nginx
type: ClusterIP
externalPort: 80
internalPort: 80
resources: {}
Deployment Pipeline: templates/service.yaml
52
apiVersion: v1
kind: Service
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.externalPort }}
targetPort: {{ .Values.service.internalPort }}
protocol: TCP
name: {{ .Values.service.name }}
selector:
app: {{ template "name" . }}
release: {{ .Release.Name }}
Deployment Pipeline: Deploy from filesystem
53
┌[luis@BigCentech-Precision5520]-(~)
└> helm upgrade --install -f dev-values.yaml myapp ./mychart
Deployment Pipeline: Helm Repo
54
└── repo
├── index.yaml
├── myapp-1.0.0.tgz
├── myapp-1.1.0.tgz
├── myapp-1.2.0.tgz
├── myapp-1.2.1.tgz
├── myapp-1.2.2.tgz
└── myapp-1.3.0.tgz
Deployment Pipeline: Helmet
55
https://hub.docker.com/r/daemonza/helmet
/
https://github.com/daemonza/helmet
Deployment Pipeline: Deploy from helm repo
56
┌[luis@BigCentech-Precision5520]-(~)
└> helm upgrade --install --version 1.2.3 -f dev-values.yaml myapp helmet/mychart
Deployment Pipeline: Stages
57
Publish Container
(on tag)
Build
(on commit)
Test
(on commit)
Deploy
(on tag)
Publish Chart
(on tag)