资源定义haproxy
#端口探测
apiVersion: v1
kind: Pod
metadata:
name: probe-demo
namespace: demo
spec:
containers:
- name: web
image: nginx
ports:
- containerPort: 8o
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 30
periodSeconds: 10
示例:执行Shell命令
livenessProbe:
exec:
command:
- cat
- /tmp/healthy
示例:HTTP请求
livenessProbe:httpGet:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
haproxy
[root@master haproxy]# cat haproxy.yml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: haproxy
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: haproxy
template:
metadata:
labels:
app: haproxy
spec:
initContainers:
- name: cp
volumeMounts:
- name: haproxy-cfg
mountPath: /tmp/
restartPolicy: Always
containers:
- image: wuqiuyao/haproxy:v3.0
imagePullPolicy: Always
env:
- name: RSs
value: "10.97.0.10 10.97.0.50"
name: haproxy
ports:
- containerPort: 80
hostPort: 80
livenessProbe:
tcpSocket:
port: 80
volumes:
- name: haproxy-cfg
emptyDir: {}
---
apiVersion: v1
kind: Service
metadata:
name: haproxy
namespace: default
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: haproxy
type: NodePort
nginx
[root@master haproxy]# cat nginx.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx1
labels:
app: nginx1
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: nginx1
template:
metadata:
labels:
app: nginx1
spec:
initContainers:
- name: in
command:
- "wget"
- "-O"
- "/usr/local/nginx/html"
- "http://www.baidu.com"
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/usr/local/nginx/html"
name: document-root
containers:
- image: best2001/nginx:v0.3
imagePullPolicy: Always
name: nginx1
---
apiVersion: v1
kind: Service
metadata:
name: nginx1
labels:
app: nginx1
spec:
ports:
- port: 80
targetPort: 80
selector:
app: nginx1
clusterIP: 10.97.0.50
apache
[root@master haproxy]# cat apache1.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd1
labels:
app: httpd1
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: httpd1
template:
metadata:
labels:
app: httpd1
spec:
containers:
- image: best2001/httpd
imagePullPolicy: Always
name: httpd1
---
apiVersion: v1
kind: Service
metadata:
name: httpd1
labels:
app: httpd1
spec:
ports:
- port: 80
targetPort: 80
selector:
app: httpd1
clusterIP: 10.97.0.10
|