Use k8s deploy Nginx service, Nginx provide services only want to deploy one of the hosts, the host does not provide other services
A. Settings tab and stains
In order to ensure that it can be assigned to nginx nginx server requires Settings tab and stains, Settings tab allows Pod choose to deploy the server, you can set the stain so that other services can not be deployed in the server Pod
The deployment nginx server IP is 192.168.1.232
Settings tab
# Settings tab key to typevalue as nginx kubectl the Node label = 192.168.1.232 of the type nginx # Look at the label kubectl the Node 192.168.1.232 --show-Labels GET NAME AGE VERSION the STATUS the ROLES LABELS 192.168.1.232 Ready <none> 30h v1.17.4 Kubernetes. io / arch = amd64, kubernetes.io / hostname = 192.168.1.232, kubernetes.io / os = linux, type = nginx
Set stain
# Key to stain node192.168.1.232 set to the value of key nginx effec NoSchedule never scheduled to # tolerations unless provided corresponding parameters in Pod kubectl taint node 192.168.1.232 key = nginx: NoSchedule
View stain
kubectl describe node 192.168.1.232
II. Set Nginx-deployment of yaml file
Nginx deployment.yaml-CAT # apiVersion: Apps / V1 kind: the Deployment Metadata: Labels: App: Nginx name: Deployment Nginx- spec: Replicas:. 1 Selector: matchLabels: App: Nginx Template: Metadata: Labels: App: Nginx spec: Containers: - Image: Nginx: 1.14.0 name: Nginx # tag selector nodeSelector: type: Nginx # stain can be provided to a corresponding scheduler server tolerations: - Key: "Key" operator: "Equal" value: "Nginx" Effect: "NoSchedule"
Application start
kubectl apply -f nginx-deployment.yaml
View has been scheduled to the corresponding server
# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deployment-57f94c46b4-5whb5 1/1 Running 0 6h30m 172.17.97.3 192.168.1.232 <none> <none>
III. Set Nginx configuration files and root directory mount
Nginx started using the default configuration file and the default web root directory, you need to use volume mount
# cat nginx-deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: nginx name: nginx-deployment spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - image: nginx:1.14.0 name: nginx volumeMounts: - name: conf mountPath: /etc/nginx - name: opt mountPath: /opt #标签选择器 nodeSelector: type: Nginx # Set stain can be scheduled to the corresponding server tolerations: - Key: "Key" operator: "Equal" value: "Nginx" Effect: "NoSchedule" Volumes: - name: the conf hostPath: path: / etc / Nginx type: Directory - name: opt hostPath: path: / opt of the type: Directory
The use of native mount hostPath mount configuration files and root directory, use the best production pvc mount
IV. Setting Service to provide services
# cat nginx-service.yaml apiVersion: v1 kind: Service metadata: labels: app: nginx name: nginx-deployment spec: ports: - port: 80 name: nginx-service80 protocol: TCP targetPort: 80 nodePort: 80 - port: 81 name: nginx-service81 protocol: TCP targetPort: 81 nodePort: 81 selector: app: nginx type: NodePort
PS: Use NodePort enable the port to provide services, if the external mapping multiple ports need to add the name of the parameter name defined parameters in port, single port without setting parameters name
k8s NodePort default mapping of external ports to other ports 30000-50000 mapping as required to modify the configuration file / opt / kubernetes / cfg / kube-apiserver, modify the port range