spring into kubernetes...$ kubectl get services name type cluster-ip external-ip port(s) age hello...
TRANSCRIPT
![Page 1: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/1.jpg)
© Copyright 2018 Pivotal Software, Inc. All rights Reserved.
Paul Czarkowski
Twitter: @pczarkowski
Spring into Kubernetes
![Page 2: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/2.jpg)
© Copyright 2018 Pivotal Software, Inc. All rights Reserved.
Paul Czarkowski
Twitter: @pczarkowski
Spring into Kubernetes
![Page 3: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/3.jpg)
![Page 4: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/4.jpg)
![Page 5: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/5.jpg)
"Kubernetes is named after the
greek god of spending money on
cloud services" - @QuinnyPig
![Page 6: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/6.jpg)
TraditionalTicketBasedHuman
Toil
Build App Artifact
Build App Container(s)
App → to the Platform
Container RuntimeContainer Hosts
CaaSContainer
Orchestrator
PaaSApplication Platform
InfrastructurePlatform
ContainerPlatform
ApplicationPlatform
InfrastructureAs
Code
More Control Less ControlLess Efficiency More Efficiency
IaaS API
CF API
K8s API
ConfigManagement
DeploymentManifest
IaaSHardwarePlatform
PXE boot ?
6
?????
PaaSApplication Platform
FunctionPlatform
??? API
![Page 7: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/7.jpg)
Containers
![Page 8: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/8.jpg)
![Page 9: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/9.jpg)
![Page 10: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/10.jpg)
Saurabh Gupta. "Containers and Pivotal Cloud Foundry" 2016.
![Page 11: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/11.jpg)
FROM maven:3.6-jdk-11-slim as BUILDCOPY . /srcWORKDIR /srcRUN mvn install -DskipTests
FROM openjdk:11.0.1-jre-slim-stretchEXPOSE 8080WORKDIR /appARG JAR=hello-0.0.1-SNAPSHOT.jar
COPY --from=BUILD /src/target/$JAR /app.jarENTRYPOINT ["java","-jar","/app.jar"]
![Page 12: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/12.jpg)
![Page 13: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/13.jpg)
$ docker build -t paulczar/hello .
$ docker push paulczar/hello
$ docker pull paulczar/hello
$ docker run -d -p 8080:8080 paulczar/hello
![Page 14: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/14.jpg)
<plugin> <groupId>com.google.cloud.tools</groupId> <artifactId>jib-maven-plugin</artifactId> <version>1.6.1</version> <configuration> <to> <image>myimage</image> </to> </configuration> </plugin>
![Page 15: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/15.jpg)
![Page 16: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/16.jpg)
![Page 17: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/17.jpg)
Kubernetes
![Page 18: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/18.jpg)
MasterMaster
Master
API Server
Users
Control Plane
Data Plane
etcdCloud CtrlManager
Worker
Kubelet
kube-proxy
docker
Scheduler
ControllerManager
Worker
Kubelet
kube-proxy
docker
Worker
Kubelet
kube-proxy
docker
Flannel Flannel Flannel
![Page 19: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/19.jpg)
Controllers
![Page 20: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/20.jpg)
Desired State
Actual State
![Page 21: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/21.jpg)
Unix Philosophy:
Do one thing. Do it well.
![Page 22: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/22.jpg)
$ kubectl
![Page 23: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/23.jpg)
Imperative
$ kubectl run hello \
--image=paulczar/go-hello-world
$ kubectl scale hello \
--replicas=3
$ kubectl create service clusterip \
hello --tcp=80:80
![Page 24: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/24.jpg)
Declarative
$ kubectl apply -f hello-world.yaml
![Page 25: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/25.jpg)
Declarative
Vs
Imperative
![Page 26: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/26.jpg)
manifests
![Page 27: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/27.jpg)
apiVersion: v1
kind: Pod
metadata:
name: hello
spec:
containers:
- image: paulczar/go-hello-world
imagePullPolicy: Always
name: hello
![Page 28: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/28.jpg)
Resources
![Page 29: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/29.jpg)
● Pods● Services
● Volumes
![Page 30: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/30.jpg)
POD
![Page 31: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/31.jpg)
one or more containers that share
a network and storage
![Page 32: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/32.jpg)
the minimum scalable unit
of your application
![Page 33: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/33.jpg)
$ kubectl
![Page 34: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/34.jpg)
$ kubectl create deployment hello \
--image=paulczar/hello
![Page 35: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/35.jpg)
● kubectl run created a deployment “deployments.apps/hello”
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/hello 1 1 1 1 1m
● The deployment created a replicaset “replicaset.apps/hello-64f6bf9dd4”
NAME DESIRED CURRENT READY AGE
replicaset.apps/hello-64f6bf9dd4 1 1 1 1m
● Which created a pod “pod/hello-64f6bf9dd4-tq5dq”
NAME READY STATUS RESTARTS AGE
pod/hello-64f6bf9dd4-tq5dq 1/1 Running 0 2s
![Page 36: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/36.jpg)
$ kubectl scale --replicas=3 \
deployment/hello
![Page 37: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/37.jpg)
$ kubectl scale --replicas=3 deployment/hello
deployment.extensions/hello scaled
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/hello-64f6bf9dd4-2bndq 1/1 Running 0 15m
pod/hello-64f6bf9dd4-4kq9l 0/1 ContainerCreating 0 2s
pod/hello-64f6bf9dd4-8lkcs 1/1 Running 0 5s
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/hello 3 3 2 3 16m
NAME DESIRED CURRENT READY AGE
replicaset.apps/hello-64f6bf9dd4 3 3 2 16m
![Page 38: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/38.jpg)
$ kubectl set env deployment/hello \
--env “MESSAGE=Hello Krakow”
![Page 39: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/39.jpg)
$ kubectl get all
NAME READY STATUS RESTARTS AGE
pod/hello-5c75b546c7-4lwnn 1/1 Running 0 1m
pod/hello-5c75b546c7-bwxxq 1/1 Running 0 1m
pod/hello-5c75b546c7-sl2pg 1/1 Running 0 1m
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
deployment.apps/hello 3 3 3 3 23m
NAME DESIRED CURRENT READY AGE
replicaset.apps/hello-5c75b546c7 3 3 3 1m
replicaset.apps/hello-64f6bf9dd4 0 0 0 23m
![Page 40: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/40.jpg)
$ kubectl get deployment hello \
-o yaml
![Page 41: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/41.jpg)
$ kubectl port-forward deployment/hello 8080
Forwarding from 127.0.0.1:8080 -> 8080
$ curl localhost:8080
<html><head><title>HELLO I LOVE YOU!!!!</title></head><body>HELLO I LOVE
YOU!!!!!</body></html>
![Page 42: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/42.jpg)
Service
![Page 43: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/43.jpg)
$ kubectl expose deployment \
hello --type=LoadBalancer \
--port 80 --target-port 8080
![Page 44: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/44.jpg)
kubectl expose deployment hello
● creates a service with a ClusterIP that acts as an internal loadbalancer to all pods in the “hello” deployment
--type=LoadBalancer
● Creates a NodePort● Configures a LoadBalancer to access the pods via the NodePort
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m
$ curl 35.184.17.129
<html><head><title>HELLO I LOVE YOU!!!!</title></head><body>HELLO I LOVE
YOU!!!!!</body></html>
![Page 45: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/45.jpg)
Servicetrack Pods based on metadata and provides connectivity and service discovery (DNS, Env variables) for them.
Type
ClusterIP (default) exposes service on a cluster-internal IP.
Container
Container
Pod
app=bacon
Container
Container
Pod
app=bacon
Service
app=bacon 10.3.55.7
![Page 46: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/46.jpg)
Servicetrack Pods based on metadata and provides connectivity and service discovery (DNS, Env variables) for them.
Type
NodePort extends ClusterIP to expose services on each node’s IP via a static port.
Container
Container
Pod
app=bacon
Container
Container
Pod
app=bacon
Service
app=bacon 10.3.55.7
192.168.0.5:4530
K8s Worker K8s Worker
192.168.0.6:4530
![Page 47: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/47.jpg)
Servicetrack Pods based on metadata and provides connectivity and service discovery (DNS, Env variables) for them.
Type
LoadBalancer extends NodePort to configure a cloud provider’s load balancer using the cloud-controller-manager.
Container
Container
Pod
app=bacon
Container
Container
Pod
app=bacon
Service
app=bacon 10.3.55.7
192.168.0.5:4530
K8s Worker K8s Worker
192.168.0.6:4530
Load Balancer33.6.5.22:80
![Page 48: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/48.jpg)
Ingressa controller that manages an external entity to provide load balancing, SSL termination and name-based virtual hosting to services based on a set of rules.
Ingress
Serviceapp=bacon
https://example.com
Serviceapp=eggs
/bacon /eggs
![Page 49: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/49.jpg)
Volume
![Page 50: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/50.jpg)
Container
Container
Pod
VolumeIs [effectively] a Directory, possibly with data in it, available to all containers in a Pod.
Usually Shares lifecycle of a Pod (Created when Pod is created, destroyed when Pod is destroyed).
Persistent Volumes outlive Pods.
Can be mounted from local disk, or from a network storage device such as a EBS volume, iscsi, NFS, etc.
![Page 51: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/51.jpg)
Config Map / Secret
![Page 52: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/52.jpg)
$ kubectl create configmap hello \
--from-literal=’message=Hello S1T’
![Page 53: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/53.jpg)
kubectl create configmap hello --from-file=index.html
● creates a configmap called “hello” containing the contents index.html
$ kubectl get configmap hello -o yaml
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"
![Page 54: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/54.jpg)
kubectl create secret generic hello --from-file=index.html
● creates a secret called “hello” containing a base64 hash of contents index.html
$ kubectl get secret hello -o yaml
apiVersion: v1
kind: Secret
metadata:
name: hello
data:
index.html:
PGh0bWw+CjxoZWFkPgoJPHRpdGxlPkhlbGxvIHRvIG15IGZyaWVuZHM8L3RpdGxlPgo8L2hlYWQ+Cjxib2R5
PgoJSGVsbG8gdG8gbXkgZnJpZW5kcwo8L2JvZHk+CjwvaHRtbD4KCg==
![Page 55: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/55.jpg)
Provides key-value pairs to be injected into a pod much like user-data is injected into a Virtual Machine in the cloud.
Allows you to do last minute configuration of applications running on Kubernetes such as setting a database host, or a admin password.
ConfigMaps store values as strings, Secrets store them as byte arrays (serialized as base64 encoded strings).
Secrets are [currently] not encrypted by default. This is likely to change.
Can be injected as files in a Volume, or as Environment Variables.
ConfigMaps/Secrets (user-data)
![Page 56: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/56.jpg)
Spring Cloud Kubernetes
![Page 57: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/57.jpg)
● Discovery● Ribbon Discovery● Dynamic Config● Profile Autoconfiguration● Istio Awareness● Pod Health Indicators
![Page 58: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/58.jpg)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-kubernetes</artifactId>
</dependency>
---
@SpringBootApplication
@EnableDiscoveryClient
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
---
@Autowired
private DiscoveryClient discoveryClient;
Service Discovery
![Page 59: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/59.jpg)
<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
![Page 60: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/60.jpg)
@SpringBootApplication
@EnableDiscoveryClient
@EnableWebFlux
public class EdgeServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EdgeServiceApplication.class, args);
}
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
spring-cloud-kubernetes-ribbon
![Page 61: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/61.jpg)
Native Service Discovery
![Page 62: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/62.jpg)
<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
![Page 63: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/63.jpg)
spring:
application:
name: cloud-k8s-app
cloud:
kubernetes:
config:
name: default-name
namespace: default-namespace
sources:
- name: c1
- namespace: n2
- namespace: n3
name: c3
spring-cloud-kubernetes-config
![Page 64: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/64.jpg)
oh and automatic prometheus metrics
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
![Page 65: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/65.jpg)
![Page 66: Spring into Kubernetes...$ kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello LoadBalancer 10.39.248.123 35.184.17.129 80:30468/TCP 5m](https://reader034.vdocuments.us/reader034/viewer/2022042219/5ec56d9503cdf255a46fb9fe/html5/thumbnails/66.jpg)
Transforming How The World Builds Software
© Copyright 2019 Pivotal Software, Inc. All rights Reserved.
@pczarkowski