k8s 安装教程请参考:http://www.javashuo.com/article/p-prmsiugp-mo.htmlhtml
Nginx安装配置参考: https://www.cnblogs.com/puroc/p/5764330.htmlnode
1、环境配置:nginx
master:192.168.0.38web
node1: 192.168.0.39docker
node2: 192.168.0.40api
安装完后用 kubectl get node 查看一下bash
2、建立configMapapp
kubectl create configmap confnginx --from-file nginx.conftcp
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; #include /etc/nginx/conf.d/*.conf; server { listen 80; server_name localhost; root /home/wwwroot/test; index index.html; } }
在两个Node上新建咱们的web访问目录: spa
3、建立nginx-rc.yaml
Replication Controller简称RC,它可以保证Pod持续运行,而且在任什么时候候都有指定数量的Pod副本,在此基础上提供一些高级特性,好比滚动升级和弹性伸缩。
apiVersion: v1 kind: ReplicationController metadata: name: nginx-controller spec: replicas: 2 selector: name: nginx template: metadata: labels: name: nginx spec: containers: - name: nginx image: docker.io/nginx:alpine ports: - containerPort: 80 volumeMounts: - mountPath: /etc/nginx/nginx.conf name: nginx-config subPath: nginx.conf - mountPath: /home/wwwroot/test name: nginx-data volumes: - name: nginx-config configMap: name: confnginx - name: nginx-data hostPath: path: /home/wwwroot/hello
kubectl create -f nginx-rc.yaml
4、建立nginx-svc.yaml
apiVersion: v1 kind: Service metadata: name: nginx-service-nodeport spec: ports: - port: 8000 targetPort: 80 protocol: TCP nodePort: 30080 #外网访问端口 type: NodePort #这个是端口类型 selector: name: nginx
kubectl create -f nginx-service.yaml
5、验证