K8s deployment & service to create a sample

######################### deployment to create a container example ##################### ########
apiVersion: Apps / v1beta1
kind: the Deployment
Metadata:
  name: Nginx-OPS
  Labels:
    App: nginx002
  namespace: OPS  
spec:
  Replicas:. 3
  Template:
    Metadata:
      Labels:
        App: nginx002
    spec:
      Containers:
      - name: nginx002
        Image: harbor.xxx.com/ops/nginx-2.2.3:v1 #docker warehouse address
        the ports:
        - containerPort: 80
#################### ####################################
# service  示例                                                                                                      #
########################################################
apiVersion: v1
kind: Service
metadata: 
  name: ops-test-nginx
  labels: 
    name: ops-test-nginx
spec:
  type: LoadBalancer
  ports:
  - port: 8099
    targetPort: 80
    protocol: TCP
  selector:
    app: nginx001
################################################
apiVersion: v1
kind: Service
metadata:
  name: ops-test-nginx02
  labels: 
    name: ops-test-nginx02
spec:
  selector:
    app: nginx002
  ports:
    - name: http
      port: 8000
      protocol: TCP
      targetPort: 80
  type: NodePort    

#####################################################################

several types of service:

ClusterIP:
Create a ClusterIP to provide access within the cluster, the default option
NodePort:
exposure to a port (NodePort) on each node IP to provide services outside the cluster to access this way: <NodeIP>: <NodePort> , and it will create a ClusterIP, use more of this type of random default port range of exposure: (30000-32767) can be explicitly specified port nodePort field
LoadBalancer:
by using load balancing and associated cloud service providers, this time nodePort and ClusterIP automatically creates
ExternalName:
to map the service name to a externalName (such as a domain name), to provide DNS CNAME record by kube-dns

Guess you like

Origin blog.csdn.net/qq_42409788/article/details/88575842