Запускаем приложение с использованием NginxInc Kubernetes Ingress
Делаю
04.04.2019
По материалам из видео индуса:
https://www.youtube.com/watch?v=YzaYqxW0wGs&list=PL34sAs7_26wNBRWM6BDhnonoA5FMERax0
Подготовили кластер и окружение как здесь.
Установили и настроили HAProxy как здесь.
Создаем NginxInc Kubernetes Ingress контроллер
Запускаем приложение
$ kubectl create -f https://raw.githubusercontent.com/justmeandopensource/kubernetes/master/yamls/ingress-demo/nginx-deploy-blue.yaml
$ kubectl create -f https://raw.githubusercontent.com/justmeandopensource/kubernetes/master/yamls/ingress-demo/nginx-deploy-green.yaml
$ kubectl create -f https://raw.githubusercontent.com/justmeandopensource/kubernetes/master/yamls/ingress-demo/ingress-resource-2.yaml
$ kubectl expose deploy nginx-deploy-blue --port 80
$ kubectl expose deploy nginx-deploy-green --port 80
$ kubectl describe ing ingress-resource-2
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deploy-blue-7cc7d854dc-9hzwf 1/1 Running 0 3m5s
nginx-deploy-green-fbbd6d8d8-2nkzb 1/1 Running 0 3m
Настройка на клиенте
# vi /etc/hosts
192.168.0.5 blue.nginx.example.com
192.168.0.5 green.nginx.example.com
$ curl blue.nginx.example.com
<h1>I am <font color=blue>BLUE</font></h1>
$ curl green.nginx.example.com
<h1>I am <font color=green>GREEN</font></h1>
Удаляем все это добро:
$ kubectl delete ing ingress-resource-2
$ kubectl delete deployment nginx-deploy-blue
$ kubectl delete deployment nginx-deploy-green
$ kubectl delete service nginx-deploy-blue
$ kubectl delete service nginx-deploy-green
Попробуем запустить свое приложение:
$ mkdir ~/tmp/cats-app/ && cd ~/tmp/cats-app/
# vi nodejs-cats-app-deployment.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nodejs-cats-app-deployment
spec:
replicas: 3
template:
metadata:
labels:
app: nodejs-cats-app
spec:
containers:
- name: nodejs-cats-app
image: webmakaka/cats-app
$ vi nodejs-cats-app-svc-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
name: nodejs-cats-app-nodeport
spec:
type: NodePort
ports:
- port: 80
targetPort: 8080
nodePort: 30123
selector:
app: nodejs-cats-app
# vi ingress-resource-nodejs-cats-app.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nodejs-cats-app-ingress
spec:
rules:
- host: nodejs-cats-app.example.com
http:
paths:
- path: /
backend:
serviceName: nodejs-cats-app-nodeport
servicePort: 80
$ kubectl create -f nodejs-cats-app-deployment.yaml
$ kubectl create -f nodejs-cats-app-svc-nodeport.yaml
$ kubectl create -f ingress-resource-nodejs-cats-app.yaml
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nodejs-cats-app-deployment-5d67fbc67d-2bmxz 1/1 Running 0 44m
nodejs-cats-app-deployment-5d67fbc67d-4jkz2 1/1 Running 0 34m
nodejs-cats-app-deployment-5d67fbc67d-ghtc5 1/1 Running 0 44m
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
nodejs-cats-app-deployment 3/3 3 3 48m
$ kubectl get ing
NAME HOSTS ADDRESS PORTS AGE
nodejs-cats-app-ingress nodejs-cats-app.example.com 80 48m
$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 66m
nodejs-cats-app-nodeport NodePort 10.110.183.157 <none> 80:30123/TCP 49m
На клиенте:
# vi /etc/hosts
192.168.0.5 nodejs-cats-app.example.com
$ curl nodejs-cats-app.example.com
OK
Удалить
# kubectl delete deployment nodejs-cats-app-deployment
# kubectl delete ing nodejs-cats-app-ingress
# kubectl delete service nodejs-cats-app-deployment
# kubectl delete svc nodejs-cats-app-nodeport