k 8 sの使用配置


アプリを作成
yamlファイルの作成
[root@localhost ~]# vim nginx.yaml 

apiVersion: v1
kind: ReplicationController
metadata:
  name: my-nginx
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 80
インテンクスを起動
[root@localhost ~]# kubectl create -f nginx.yaml 
replicationcontroller "my-nginx" created
[root@localhost ~]# kubectl get pods
NAME             READY     STATUS              RESTARTS   AGE
my-nginx-lwr99   0/1       ContainerCreating   0          7s
ログを見る
[root@localhost ~]# kubectl describe pod my-nginx-lwr99
Name:       my-nginx-lwr99
Namespace:  default
Node:       192.168.56.202/192.168.56.202
Start Time: Mon, 23 Apr 2018 14:24:57 +0800
Labels:     app=nginx
Status:     Running
IP:     172.30.55.2
Controllers:    ReplicationController/my-nginx
Containers:
  nginx:
    Container ID:   docker://4a01698fd122030de55c5b1caf42b256e28fe7264d32f97b4c89fdd0ab34f83d
    Image:      nginx
    Image ID:       docker-pullable://docker.io/nginx@sha256:18156dcd747677b03968621b2729d46021ce83a5bc15118e5bcced925fb4ebb9
    Port:       80/TCP
    Limits:
      cpu:  500m
      memory:   128Mi
    Requests:
      cpu:          500m
      memory:           128Mi
    State:          Running
      Started:          Mon, 23 Apr 2018 14:25:18 +0800
    Ready:          True
    Restart Count:      0
    Volume Mounts:      
    Environment Variables:  
Conditions:
  Type      Status
  Initialized   True 
  Ready     True 
  PodScheduled  True 
No volumes.
QoS Class:  Guaranteed
Tolerations:    
Events:
  FirstSeen LastSeen    Count   From                SubObjectPath       Type        Reason          Message
  --------- --------    -----   ----                -------------       --------    ------          -------
  54s       54s     1   {default-scheduler }                    Normal      Scheduled       Successfully assigned my-nginx-lwr99 to 192.168.56.202
  50s       50s     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulling         pulling image "nginx"
  54s       34s     2   {kubelet 192.168.56.202}                Warning     MissingClusterDNS   kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  34s       34s     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulled          Successfully pulled image "nginx"
  34s       34s     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Created         Created container with docker id 4a01698fd122; Security:[seccomp=unconfined]
  33s       33s     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Started         Started container with docker id 4a01698fd122
結果を表示
[root@localhost ~]# kubectl get pods
NAME             READY     STATUS    RESTARTS   AGE
my-nginx-lwr99   1/1       Running   0          1m
nodeで結果を見る
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                                                        COMMAND                  CREATED              STATUS              PORTS               NAMES
4a01698fd122        nginx                                                        "nginx -g 'daemon ..."   46 seconds ago       Up 44 seconds                           k8s_nginx.cf5bec70_my-nginx-lwr99_default_0b2a62a8-46bf-11e8-94fc-000c29619eeb_2d98d52a
ce5d302bc2ed        registry.access.redhat.com/rhel7/pod-infrastructure:latest   "/usr/bin/pod"           About a minute ago   Up About a minute                       k8s_POD.a8590b41_my-nginx-lwr99_default_0b2a62a8-46bf-11e8-94fc-000c29619eeb_cf234267
動的追加プロファイル
上で作成したアプリに対して、次の実行コマンドを動的に追加します.
kubectl scale replicationcontroller --replicas=2 my-nginx
[root@localhost ~]# kubectl scale replicationcontroller --replicas=2 my-nginx
replicationcontroller "my-nginx" scaled
[root@localhost ~]# kubectl get pods
NAME             READY     STATUS              RESTARTS   AGE
my-nginx-8m40c   0/1       ContainerCreating   0          12s
my-nginx-lwr99   1/1       Running             0          22m
[root@localhost ~]# kubectl get rc
NAME       DESIRED   CURRENT   READY     AGE
my-nginx   2         2         2         25m
結果を表示
[root@localhost ~]# kubectl describe pod my-nginx
Name:       my-nginx-8m40c
Namespace:  default
Node:       192.168.56.201/192.168.56.201
Start Time: Mon, 23 Apr 2018 14:47:31 +0800
Labels:     app=nginx
Status:     Running
IP:     172.30.31.2
Controllers:    ReplicationController/my-nginx
Containers:
  nginx:
    Container ID:   docker://925085542d0d105693f72f4b4f727367aa8df69505e2424a90a19df27928bd09
    Image:      nginx
    Image ID:       docker-pullable://docker.io/nginx@sha256:18156dcd747677b03968621b2729d46021ce83a5bc15118e5bcced925fb4ebb9
    Port:       80/TCP
    Limits:
      cpu:  500m
      memory:   128Mi
    Requests:
      cpu:          500m
      memory:           128Mi
    State:          Running
      Started:          Mon, 23 Apr 2018 14:47:50 +0800
    Ready:          True
    Restart Count:      0
    Volume Mounts:      
    Environment Variables:  
Conditions:
  Type      Status
  Initialized   True 
  Ready     True 
  PodScheduled  True 
No volumes.
QoS Class:  Guaranteed
Tolerations:    
Events:
  FirstSeen LastSeen    Count   From                SubObjectPath       Type        Reason          Message
  --------- --------    -----   ----                -------------       --------    ------          -------
  12m       12m     1   {default-scheduler }                    Normal      Scheduled       Successfully assigned my-nginx-8m40c to 192.168.56.201
  12m       12m     1   {kubelet 192.168.56.201}    spec.containers{nginx}  Normal      Pulling         pulling image "nginx"
  12m       12m     2   {kubelet 192.168.56.201}                Warning     MissingClusterDNS   kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  12m       12m     1   {kubelet 192.168.56.201}    spec.containers{nginx}  Normal      Pulled          Successfully pulled image "nginx"
  12m       12m     1   {kubelet 192.168.56.201}    spec.containers{nginx}  Normal      Created         Created container with docker id 925085542d0d; Security:[seccomp=unconfined]
  12m       12m     1   {kubelet 192.168.56.201}    spec.containers{nginx}  Normal      Started         Started container with docker id 925085542d0d

Name:       my-nginx-lwr99
Namespace:  default
Node:       192.168.56.202/192.168.56.202
Start Time: Mon, 23 Apr 2018 14:24:57 +0800
Labels:     app=nginx
Status:     Running
IP:     172.30.55.2
Controllers:    ReplicationController/my-nginx
Containers:
  nginx:
    Container ID:   docker://4a01698fd122030de55c5b1caf42b256e28fe7264d32f97b4c89fdd0ab34f83d
    Image:      nginx
    Image ID:       docker-pullable://docker.io/nginx@sha256:18156dcd747677b03968621b2729d46021ce83a5bc15118e5bcced925fb4ebb9
    Port:       80/TCP
    Limits:
      cpu:  500m
      memory:   128Mi
    Requests:
      cpu:          500m
      memory:           128Mi
    State:          Running
      Started:          Mon, 23 Apr 2018 14:25:18 +0800
    Ready:          True
    Restart Count:      0
    Volume Mounts:      
    Environment Variables:  
Conditions:
  Type      Status
  Initialized   True 
  Ready     True 
  PodScheduled  True 
No volumes.
QoS Class:  Guaranteed
Tolerations:    
Events:
  FirstSeen LastSeen    Count   From                SubObjectPath       Type        Reason          Message
  --------- --------    -----   ----                -------------       --------    ------          -------
  35m       35m     1   {default-scheduler }                    Normal      Scheduled       Successfully assigned my-nginx-lwr99 to 192.168.56.202
  35m       35m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulling         pulling image "nginx"
  35m       35m     2   {kubelet 192.168.56.202}                Warning     MissingClusterDNS   kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  35m       35m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulled          Successfully pulled image "nginx"
  35m       35m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Created         Created container with docker id 4a01698fd122; Security:[seccomp=unconfined]
  35m       35m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Started         Started container with docker id 4a01698fd122

[root@localhost ~]# 
ノードの削除
[root@localhost ~]# kubectl get node
NAME             STATUS    AGE
192.168.56.201   Ready     4d
192.168.56.202   Ready     4d
[root@localhost ~]# kubectl delete node 192.168.56.201
node "192.168.56.201" deleted
[root@localhost ~]# kubectl get node
NAME             STATUS    AGE
192.168.56.202   Ready     4d
上の実行コマンドが終了したら、k 8 sは現在ノードが一つしかないことが分かりました.しかし、サーバーはまだ2つです.
[root@localhost ~]# kubectl get pods
NAME             READY     STATUS    RESTARTS   AGE
my-nginx-lwr99   1/1       Running   0          38m
my-nginx-wwv4j   1/1       Running   0          47s
再びdescribeはip端末が同じセグメントから来ていることを発見しました.
[root@localhost ~]# kubectl describe pod my-nginx
Name:       my-nginx-lwr99
Namespace:  default
Node:       192.168.56.202/192.168.56.202
Start Time: Mon, 23 Apr 2018 14:24:57 +0800
Labels:     app=nginx
Status:     Running
IP:     172.30.55.2
Controllers:    ReplicationController/my-nginx
Containers:
  nginx:
    Container ID:   docker://4a01698fd122030de55c5b1caf42b256e28fe7264d32f97b4c89fdd0ab34f83d
    Image:      nginx
    Image ID:       docker-pullable://docker.io/nginx@sha256:18156dcd747677b03968621b2729d46021ce83a5bc15118e5bcced925fb4ebb9
    Port:       80/TCP
    Limits:
      cpu:  500m
      memory:   128Mi
    Requests:
      cpu:          500m
      memory:           128Mi
    State:          Running
      Started:          Mon, 23 Apr 2018 14:25:18 +0800
    Ready:          True
    Restart Count:      0
    Volume Mounts:      
    Environment Variables:  
Conditions:
  Type      Status
  Initialized   True 
  Ready     True 
  PodScheduled  True 
No volumes.
QoS Class:  Guaranteed
Tolerations:    
Events:
  FirstSeen LastSeen    Count   From                SubObjectPath       Type        Reason          Message
  --------- --------    -----   ----                -------------       --------    ------          -------
  40m       40m     1   {default-scheduler }                    Normal      Scheduled       Successfully assigned my-nginx-lwr99 to 192.168.56.202
  40m       40m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulling         pulling image "nginx"
  40m       40m     2   {kubelet 192.168.56.202}                Warning     MissingClusterDNS   kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  40m       40m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulled          Successfully pulled image "nginx"
  40m       40m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Created         Created container with docker id 4a01698fd122; Security:[seccomp=unconfined]
  40m       40m     1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Started         Started container with docker id 4a01698fd122

Name:       my-nginx-wwv4j
Namespace:  default
Node:       192.168.56.202/192.168.56.202
Start Time: Mon, 23 Apr 2018 15:02:36 +0800
Labels:     app=nginx
Status:     Running
IP:     172.30.55.3
Controllers:    ReplicationController/my-nginx
Containers:
  nginx:
    Container ID:   docker://b3446831953f87524167b134e863be44d1d55093344df41bb2d8c11b4a348966
    Image:      nginx
    Image ID:       docker-pullable://docker.io/nginx@sha256:18156dcd747677b03968621b2729d46021ce83a5bc15118e5bcced925fb4ebb9
    Port:       80/TCP
    Limits:
      cpu:  500m
      memory:   128Mi
    Requests:
      cpu:          500m
      memory:           128Mi
    State:          Running
      Started:          Mon, 23 Apr 2018 15:02:51 +0800
    Ready:          True
    Restart Count:      0
    Volume Mounts:      
    Environment Variables:  
Conditions:
  Type      Status
  Initialized   True 
  Ready     True 
  PodScheduled  True 
No volumes.
QoS Class:  Guaranteed
Tolerations:    
Events:
  FirstSeen LastSeen    Count   From                SubObjectPath       Type        Reason          Message
  --------- --------    -----   ----                -------------       --------    ------          -------
  2m        2m      1   {default-scheduler }                    Normal      Scheduled       Successfully assigned my-nginx-wwv4j to 192.168.56.202
  2m        2m      1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulling         pulling image "nginx"
  2m        2m      2   {kubelet 192.168.56.202}                Warning     MissingClusterDNS   kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Falling back to DNSDefault policy.
  2m        2m      1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Pulled          Successfully pulled image "nginx"
  2m        2m      1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Created         Created container with docker id b3446831953f; Security:[seccomp=unconfined]
  2m        2m      1   {kubelet 192.168.56.202}    spec.containers{nginx}  Normal      Started         Started container with docker id b3446831953f

[root@localhost ~]# 
新しいnodeを追加します
削除したばかりのnode上でノードを新たに起動し、次のコマンドを実行します.
[root@localhost ~]# systemctl start kubelet
[root@localhost ~]# systemctl restart kubelet
Mから結果を見る
[root@localhost ~]# kubectl get node
NAME             STATUS    AGE
192.168.56.201   Ready     12s
192.168.56.202   Ready     4d
外部ネットワークにアクセスできる追加
上のアプリは外部ネットワークにアクセスできません.外部ネットワークにアクセスするにはserviceサービスを作成する必要があります.
[root@localhost ~]# cat nginxsrc.yaml 
apiVersion: v1 
kind: Service 
metadata: 
  name: nginx-service 
spec: 
  externalIPs: 
    - 192.168.56.200 
  ports: 
  - port: 8000 
    targetPort: 80 
    protocol: TCP 
  selector: 
    app: nginx
https://www.58jb.com/html/180.htmlhttps://www.cnblogs.com/junneyang/p/6274689.html