本篇筆記將介紹探測 Container 的功能, 分為兩種:
# Wishlist deployment yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: wishlist-deployment
labels:
app: wishlist
spec:
replicas: 3 #We always want more than 1 replica for HA
selector:
matchLabels:
app: wishlist
template:
metadata:
labels:
app: wishlist
spec:
containers:
- name: wishlist #1st container
image: karthequian/wishlist:1.0 #Dockerhub image
ports:
- containerPort: 8080 #Exposes the port 8080 of the container
name: wishlist-port
env:
- name: PORT #Environment variable key passed to container that is read by application
value: "8080" # Value of the env port.
livenessProbe:
httpGet:
path: /status
port: 8080 #Name or port number
initialDelaySeconds: 5
timeoutSeconds: 1
- name: catalog #2nd container
image: karthequian/wishlist-catalog:1.0
ports:
- containerPort: 8081
name: catalog-port
env:
- name: PORT
value: "8081"
livenessProbe:
httpGet:
path: /status
port: 8081 #Name or port number
initialDelaySeconds: 5
timeoutSeconds: 1
- name: auth #3rd container
image: karthequian/wishlist-auth:1.0
ports:
- containerPort: 8082
name: auth-port
env:
- name: PORT
value: "8082"
livenessProbe:
httpGet:
path: /status
port: 8082 #Name or port number
initialDelaySeconds: 5
timeoutSeconds: 1
---
kind: Service
apiVersion: v1
metadata:
name: wishlist-service
namespace: default
spec:
type: NodePort
selector:
app: wishlist
ports:
- name: wishlist-port
protocol: TCP
port: 8080
targetPort: 8080
- name: wishlist-auth-port
protocol: TCP
port: 8081
targetPort: 8081
- name: wishlist-catalog-port
protocol: TCP
port: 8082
targetPort: 8082
PS C:\k8s> kubectl apply -f .\wishlist-deployment-liveness.yaml
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
deployment.apps "wishlist-deployment" configured
Warning: kubectl apply should be used on resource created by either kubectl create --save-config or kubectl apply
service "wishlist-service" configured
Name: wishlist-deployment
Namespace: default
CreationTimestamp: Wed, 24 Oct 2018 01:16:03 +0800
Labels: app=wishlist
Annotations: deployment.kubernetes.io/revision=2
kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"labels":{"app":"wishlist"},"name":"wishlist-deployment","namespace":"default"...
Selector: app=wishlist
Replicas: 3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType: RollingUpdate
MinReadySeconds: 0
RollingUpdateStrategy: 25% max unavailable, 25% max surge
Pod Template:
Labels: app=wishlist
Containers:
wishlist:
Image: karthequian/wishlist:1.0
Port: 8080/TCP
Host Port: 0/TCP
Liveness: http-get http://:8080/status delay=5s timeout=1s period=10s #success=1 #failure=3
Environment:
PORT: 8080
Mounts: <none>
catalog:
Image: karthequian/wishlist-catalog:1.0
Port: 8081/TCP
Host Port: 0/TCP
Liveness: http-get http://:8081/status delay=5s timeout=1s period=10s #success=1 #failure=3
Environment:
PORT: 8081
Mounts: <none>
auth:
Image: karthequian/wishlist-auth:1.0
Port: 8082/TCP
Host Port: 0/TCP
Liveness: http-get http://:8082/status delay=5s timeout=1s period=10s #success=1 #failure=3
Environment:
PORT: 8082
Mounts: <none>
Volumes: <none>
Conditions:
Type Status Reason
---- ------ ------
Available True MinimumReplicasAvailable
Progressing True NewReplicaSetAvailable
OldReplicaSets: <none>
NewReplicaSet: wishlist-deployment-bf8f7946c (3/3 replicas created)
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set wishlist-deployment-bf8f7946c to 1
Normal ScalingReplicaSet 3m deployment-controller Scaled down replica set wishlist-deployment-6cb7f6c4c9 to 2
Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set wishlist-deployment-bf8f7946c to 2
Normal ScalingReplicaSet 3m deployment-controller Scaled down replica set wishlist-deployment-6cb7f6c4c9 to 1
Normal ScalingReplicaSet 3m deployment-controller Scaled up replica set wishlist-deployment-bf8f7946c to 3
Normal ScalingReplicaSet 3m deployment-controller Scaled down replica set wishlist-deployment-6cb7f6c4c9 to 0
以上便設定好 liveness probe 了.