一、下载ingress-nginx deploy.yaml文件
deploy.yamldeploy.yaml
修改Service的类型为NodePort, 修改 deploy.yaml,Deployment->spec->template->spec加入hostNetwork: true,以便从节点的ip直接访问,由于文件里image是从k8s.gcr.io/ingress-nginx上拉取,需要到registry.hub.docker.com找到与文件中相同的版本的image,用找到的地址替换掉k8s.gcr.io/ingress-nginx/controller:v1.0.0,相同的方法替换掉k8s.gcr.io/ingress-nginx/kube-webhook-certgen:v1.0的image。
为了让Ingress 支持tcp服务(把mysql用ingress),加入--tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
二、执行 kubectl apply -f deploy.yaml 安装ingress-nginx, kubectl get po -n ingress-nginx查看安装情况,可以看到ingress-controller已经在192.168.56.103上了
用curl命令验证curl 192.168.56.103/healthz -i
三、安装postgres验证Ingress
新建postgres-deployment.yaml文件,执行kubectl apply -f postgres-deployment.yaml
---
apiVersion: v1
kind: Service
metadata:
name: postgresql
spec:
ports:
- port: 5432
selector:
run: postgresql
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: postgresql
name: postgresql
namespace: default
spec:
replicas: 1
selector:
matchLabels:
run: postgresql
strategy:
type: Recreate
template:
metadata:
labels:
run: postgresql
tier: postgresql
spec:
containers:
- image: postgres
imagePullPolicy: IfNotPresent
name: postgresql
env:
- name: POSTGRES_USER
value: "*****"
- name: POSTGRES_DB
value: gitlabhq_production
- name: POSTGRES_PASSWORD
value: *****
ports:
- containerPort: 5432
name: postgresql
volumeMounts:
- mountPath: "/var/lib/postgresql/data"
name: "mendix-pgdata"
volumes:
- name: mendix-pgdata
hostPath:
path: /home/docker/pgdata
执行 kubectl get svc,可以看到postgresssql的类型为ClusterIP
新建configmap文件tcp-services.yaml,kubectl apply -f tcp-services.yaml建立configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: tcp-services
namespace: ingress-nginx
data:
5432: "default/postgresql:5432"
连接192.168.56.103postgresql。成功