Client access mode 03 for binary installation of kubernetes1.14.1-pod configuration list

View pod configuration list

Reference resources: (https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.14/)
[root@k8s-master01 ~]# kubectl  explain pods.metadata.[.........]
[root@k8s-master01 ~]# kubectl  explain pods.spec.[........]

Open Port+ip Address Access: Once bound here, only specified IP or port access is allowed

    [root@k8s-master01 ~]# kubectl  explain pods.spec.containers.ports
      containerPort : Container Open Port
        hostIP:  Bind Host ip
        hostPort: Bind host port
        name:  Must be IANA_SVC_NAME,And yes pod Only
        protocol : Protocol port must be UDP TCP SCTP Type, default TCP
        //Grammar:
     spec:
     containers:
     - image: nginx
       imagePullPolicy: IfNotPresent
       name: nginx-1
       ports:
               -  protocol: TCP
                  conainerPort: 80
                  name: http
                    hostPort: 8888
    [root@k8s-master01 ~]# cat nginx_pods.yaml 
     apiVersion: v1
     kind: Pod
     metadata:
       name: pod-demo1
       namespace:  prod
     spec:
       containers:
       - image: nginx
         imagePullPolicy: IfNotPresent
         name: nginx-1
         ports:
         - protocol: TCP
           containerPort: 80
           hostPort: 8888
           name: http-nginx
[root@k8s-master01 ~]# kubectl  apply -f nginx_pods.yaml            
[root@k8s-master01 ~]# kubectl  get pods/pod-demo1 -n prod -o wide

Switch to Server 29 View

Access Test

Bind host IP

 ports: 
   - protocol: TCP
 containerPort: 80
 hostPort: 8888
 name: http-nginx
 hostIP: 192.168.1.101

How external clients access internal ip addresses

service->Nodeport
    [root@k8s-master01 ~]# kubectl  create service clusterip nginx-dep --tcp=80:80
         Direct access (all nodes are accessible) depending on the number of open nodes
The above instances of hostPort can only be accessed by the ip+port of the specified node
hostNetwork can only access the specified host ip+port
    spec:
      containers:
      - image: nginx
        imagePullPolicy: IfNotPresent
        name: nginx-1
      hostNetwork: true

Tags: Linux Nginx Kubernetes

Posted on Thu, 07 Nov 2019 13:07:16 -0800 by stirton