Simple and practical k8s of NodePort type of Label and Service

Said last major one type of service, clusterIp, said the next NodePort. Source: https://github.com/limingios/docker/tree/master/No.10

Create a service by pod

  • Enter service in the labs directory

 

 cd deployk8s-master
 cd labs
 cd services

  • View nginx-pod

 

apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
  labels:
    app: nginx
spec:
  containers:
  - name: nginx-container
    image: nginx
    ports:
    - name: nginx-port
      containerPort: 8

 

kubectl create -f pod_nginx.yml 
kubectl get pods

  • Create a service type is nodePort

The default form of type clusterIP

 

kubectl expose pods nginx-pod -h
expose pods nginx-pod --type=NodePort
kubectl describe node

image.png

I understand what yet? In fact nodePort is exposed directly to a port, you can directly access, and cool is cool but unsafe.

Create a service through pod according to the form yml file

  • Delete service

pod still, service has been successfully removed, app must correspond.

 

kubectl delete service nginx-pod
kubectl get pods
kubectl get svc
get pods --show-labels
more service_nginx.yml 

image.png

  • Create a service

 

kubectl create -f service_nginx.yml
vim service_nginx.yml 

  • label of understanding

Label K8S mechanism is an important design objects through a weak association Label, flexible classification and selection of different services or business services allow users to deploy loosely coupled manner according to their specific organizational structure.
Label is a pair of KV, very meaningful to the user, but there is no direct significance to K8S itself. Label can be specified when creating an object, can also be modified at a later stage, each object can have multiple labels, but the key value must be unique.
Label can be freely defined, but suggested readability, such as setting Pod application name and version number. In addition Lable is not unique, in order to more accurately identify the resource target should be set for the label multi-dimensional resource object.

nodePort all the pod can be used, if used nodePort, then take up a lot of ports, it is not very resource intensive! label put on it as an alias, easy to operate designated pod.

Published 382 original articles · won praise 306 · views 40000 +

Guess you like

Origin blog.csdn.net/lixinkuan328/article/details/103993666