06 - Spring Into Kubernetes - Paul Czarkowski
06 - Spring Into Kubernetes - Paul Czarkowski
06 - Spring Into Kubernetes - Paul Czarkowski
Kubernetes
Paul Czarkowski
Twitter: @pczarkowski
© Copyright 2018 Pivotal Software, Inc. All rights Reserved.
Spring into
Kubernetes
Paul Czarkowski
Twitter: @pczarkowski
© Copyright 2018 Pivotal Software, Inc. All rights Reserved.
"Kubernetes is named after the
greek god of spending money on
cloud services" - @QuinnyPig
More Control Less Control
Less Efficiency More Efficiency
Infrastructure
Container Runtime
PXE boot ? Container Hosts
Platform
Hardware
IaaS
Platform
6
Containers
Saurabh Gupta. "Containers and Pivotal Cloud Foundry" 2016.
FROM maven:3.6-jdk-11-slim as BUILD
COPY . /src
WORKDIR /src
RUN mvn install -DskipTests
FROM openjdk:11.0.1-jre-slim-stretch
EXPOSE 8080
WORKDIR /app
ARG JAR=hello-0.0.1-SNAPSHOT.jar
Control Plane
API Controller
Server Manager
etcd
Cloud Ctrl
Scheduler
Manager
Master
Master
Master
Data Plane
Vs
Imperative
manifests
apiVersion: v1
kind: Pod
metadata:
name: hello
spec:
containers:
- image: paulczar/go-hello-world
imagePullPolicy: Always
name: hello
Resources
● Pods
● Services
● Volumes
POD
one or more containers that share
a network and storage
the minimum scalable unit
of your application
$ kubectl
$ kubectl create deployment hello \
--image=paulczar/hello
● kubectl run created a deployment “deployments.apps/hello”
$ curl localhost:8080
<html><head><title>HELLO I LOVE YOU!!!!</title></head><body>HELLO I LOVE
YOU!!!!!</body></html>
Service
$ kubectl expose deployment \
hello --type=LoadBalancer \
--port 80 --target-port 8080
kubectl expose deployment hello
--type=LoadBalancer
● Creates a NodePort
● Configures a LoadBalancer to access the pods via the NodePort
$ curl 35.184.17.129
<html><head><title>HELLO I LOVE YOU!!!!</title></head><body>HELLO I LOVE
YOU!!!!!</body></html>
Service
Pod Pod
192.168.0.5:4530 192.168.0.6:4530
Type
app=bacon app=bacon
NodePort extends ClusterIP to expose services on
Container Container
each node’s IP via a static port.
Container Container
Pod Pod
33.6.5.22:80
Load Balancer
192.168.0.5:4530 192.168.0.6:4530
Container Container
Pod Pod
https://example.com
Ingress Ingress
a controller that manages an external entity to provide
/bacon /eggs load balancing, SSL termination and name-based
virtual hosting to services based on a set of rules.
Service Service
app=bacon app=eggs
Volume
Volume
Is [effectively] a Directory, possibly with data in it,
available to all containers in a Pod.
apiVersion: v1
kind: ConfigMap
metadata:
name: hello
data:
index.html: "<html>\n<head>\n\t<title>Hello to my
friends</title>\n</head>\n<body>\n\tHello
to my friends\n</body>\n</html>\n\n"
kubectl create secret generic hello --from-file=index.html
apiVersion: v1
kind: Secret
metadata:
name: hello
data:
index.html:
PGh0bWw+CjxoZWFkPgoJPHRpdGxlPkhlbGxvIHRvIG15IGZyaWVuZHM8L3RpdGxlPgo8L2hlYWQ+Cjxib2R5
PgoJSGVsbG8gdG8gbXkgZnJpZW5kcwo8L2JvZHk+CjwvaHRtbD4KCg==
ConfigMaps/Secrets (user-data)
Provides key-value pairs to be injected into a pod much like user-data is injected into a Virtual
Machine in the cloud.
ConfigMaps store values as strings, Secrets store them as byte arrays (serialized as base64
encoded strings).
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-ribbon</artifactId>
</dependency>
spring-cloud-kubernetes-ribbon
@SpringBootApplication
@EnableDiscoveryClient
@EnableWebFlux
public class EdgeServiceApplication {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
Native Service Discovery
spring-cloud-kubernetes-config
<dependencies>
<!-- needed for spring kubernetes config reloads -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- spring cloud kubernetes config server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes-config</artifactId>
</dependency>
</dependencies>
spring-cloud-kubernetes-config
spring:
application:
name: cloud-k8s-app
cloud:
kubernetes:
config:
name: default-name
namespace: default-namespace
sources:
- name: c1
- namespace: n2
- namespace: n3
name: c3
oh and automatic prometheus
metrics
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
Transforming How The World Builds Software
@pczarkowski