เริ่มการใช้งาน Kubernetes แบบเร็วๆ
- master node : 10.0.0.10
- node-1 : 10.0.0.11
- node-2 : 10.0.0.12
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpd
spec:
replicas: 2
selector:
matchLabels:
app.kubernetes.io/name: httpd
template:
metadata:
labels:
app.kubernetes.io/name: httpd
spec:
containers:
- name: httpd
image: httpd
imagePullPolicy: Always
ports:
- containerPort: 80
apiVersion: v1
kind: Service
metadata:
name: httpd
spec:
type: NodePort
ports:
- port: 80
nodePort: 30001
name: http
selector:
app.kubernetes.io/name: httpd
$ kubectl apply -f httpd.deployment.yaml
$ kubectl apply -f httpd.service.yaml
$ kubectl get service
$ sudo apt-get install nginx -y
upstream 10.0.0.10 {
server 10.0.0.11:30001;
server 10.0.0.12:30001;
}
server {
listen 80;
location / {
proxy_pass http://10.0.0.10;
}
}
$ sudo /etc/init.d/nginx reload
#or
$ systemctl restart nginx