Environment:
Two virtual machines,
10.10.20.203 deploying Docker, ETCD, flannel, Kube-apiserver, Kube-controller-manager, Kube-scheduler
10.10.20.206 deploying Docker, Flannel, Kubelet, Kube-proxy
1. Create Nginx-rc.yaml
apiVersion:v1kind:ReplicationControllermetadata: name:nginx-controllerspec: 2 selector: name:nginx Template: metadata: Labels: name:nginx Spec: Containers: - Name:nginx image:nginx ports:
2. Create Nginx-service-nodeport.yaml
apiVersion:v1kind:Servicemetadata: name:nginx-service-nodeportspec: ports: 8000 protocol:tcp type:nodeport selector: Name:nginx
3. Create pod
Kubectl create-f Nginx-rc.yaml
4. Create service
Kubectl create-f Nginx-service-nodeport.yaml
5. View Pod
[Email protected] ~]# kubectl get Podsname Ready STATUS restarts agenginx-controller-v40nj 1/1 Running 1 1hnginx-controller-zxdzh 1/1 Running 1 1h
[Email protected] ~]# kubectl describe pod nginx-controller-V40njname:nginx-controller-v40njNamespace:defaultNode:k8s-slave1-206/60.19.29.21Start Time:thu, OneThe . +: Geneva: --0700Labels:name=NGINXSTATUS:RUNNINGIP:10.0.83.3Controllers:replicationcontroller/nginx-ControllerContainers:nginx:Container Id:docker://269adc9b693aba0356ba18e4253c2b498fc7b7a8ce0af83857fcfd6b70e6ef03Image:nginx Image id:docker://sha256:0d409d33b27e47423b049f7f863faa08655a8c901749c2b25b93ca67d01a470dPort: the/TCP state:running Started:thu, OneThe . -: the: --0700Last state:terminated reason:completed Exit Code:0Started:thu, OneThe . +:Geneva: --0700Finished:thu, OneThe . -: A: A-0700ready:true Restart Count:1Environment Variables:<none>Conditions:type Status Initialized true Ready True podscheduled trueno volumes. QoS Tier:BestEffortEvents:FirstSeen lastseen Count from Subobjectpath Type Rea Son Message--------- -------- ----- ---- ------------- -------- ------ -------5m 5m1{Kubelet k8s-slave1-206} Spec.containers{nginx} Normal pulling pulling image"Nginx"5m 5m2{Kubelet k8s-slave1-206} Warning Missingclusterdns Kubelet does not has CLUSTERDNS IP configured and cannot create Pod Using"Clusterfirst"policy. Falling back to Dnsdefault policy. 5m 5m1{Kubelet k8s-slave1-206} Spec.containers{nginx} Normal pulled successfully pulled image"Nginx"5m 5m1{Kubelet k8s-slave1-206} Spec.containers{nginx} Normal Created Created container with DockerID269adc9b693a 5m 5m1{Kubelet k8s-slave1-206} Spec.containers{nginx} Normal Started Started container with DockerID269adc9b693a
6. View Service
[Email protected] ~]# kubectl get ServiceNAME CLUSTER-ip external-IP PORT (S) agekubernetes 10.254. 0.1 <none> 443/TCP 16hnginx-service-nodeport 10.254 . 29.72 <nodes> 8000/tcp 49m
[Email protected] ~]# Kubectl describe service nginx-service-Nodeportname:nginx-service-Nodeportnamespace:defaultlabels:<none>Selector:name=Nginxtype:nodeportip:10.254.29.72Port:<unset>8000/Tcpnodeport:<unset>31152/tcpendpoints:10.0.83.2: the,10.0.83.3: theSession Affinity:noneno events.
7, test service is useful
Because the service uses the Nodeport method, access to the 31152 port on any one node can access Nginx
$ curl10.10.20.203:31152<! DOCTYPE html>Head><title>welcome to Nginx!</title><style>body {width:35em; Margin:0Auto; Font-family:tahoma, Verdana, Arial, sans-serif; }</style></Head><body>If you see this page, the Nginx Web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and refer<a href="http://nginx.org/">nginx.org</a>.<br/>commercial support was available at<a href="http://nginx.com/">nginx.com</a>.</p><p><em>thank forUsing nginx.</em></p></body>$ curl10.10.20.206:31152<! DOCTYPE html>Head><title>welcome to Nginx!</title><style>body {width:35em; Margin:0Auto; Font-family:tahoma, Verdana, Arial, sans-serif; }</style></Head><body>If you see this page, the Nginx Web server is successfully installed andworking. Further configuration is required.</p><p>For online documentation and refer<a href="http://nginx.org/">nginx.org</a>.<br/>commercial support was available at<a href="http://nginx.com/">nginx.com</a>.</p><p><em>thank forUsing nginx.</em></p></body>k8s Deploying Nginx Clusters