Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add local storage to downwards API#50435

Merged
k8s-github-robot merged 2 commits into
kubernetes:masterfrom
NickrenREN:localstorage-downwardapi
Aug 29, 2017
Merged

Add local storage to downwards API#50435
k8s-github-robot merged 2 commits into
kubernetes:masterfrom
NickrenREN:localstorage-downwardapi

Conversation

@NickrenREN
Copy link
Copy Markdown
Contributor

@NickrenREN NickrenREN commented Aug 10, 2017

Release note:

Add local ephemeral storage to downward API 

/assign @NickrenREN

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 10, 2017
@k8s-github-robot k8s-github-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/L Denotes a PR that changes 100-499 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Aug 10, 2017
@NickrenREN
Copy link
Copy Markdown
Contributor Author

/test pull-kubernetes-unit

@NickrenREN NickrenREN force-pushed the localstorage-downwardapi branch from 4c07f6f to 126fe8a Compare August 10, 2017 14:52
@NickrenREN NickrenREN changed the title [WIP]: Add local storage to downwards API Add local storage to downwards API Aug 10, 2017
@NickrenREN
Copy link
Copy Markdown
Contributor Author

/release-note

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Aug 10, 2017
@NickrenREN
Copy link
Copy Markdown
Contributor Author

/unassign
/assign @jingxu97
cc @ddysher

@k8s-ci-robot k8s-ci-robot assigned jingxu97 and unassigned NickrenREN Aug 10, 2017
@NickrenREN
Copy link
Copy Markdown
Contributor Author

NickrenREN commented Aug 11, 2017

Hi, @jingxu97 @ddysher
fyi:
I ran kubernetes with this PR, and created pod using yaml file:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-envars-fieldref
spec:
  containers:
    - name: test-container
      image: nginx
      imagePullPolicy: IfNotPresent
      command: [ "sh", "-c"]
      args:
      - while true; do
          echo -en '\n';
          printenv MY_NODE_NAME MY_POD_NAME SCRATCH_VOLUME;
          sleep 10;
        done;
      resources:
        requests:
          memory: "32Mi"
          cpu: "125m"
          storage.kubernetes.io/overlay: "500Mi"
        limits:
          memory: "64Mi"
          cpu: "250m"
          storage.kubernetes.io/overlay: "1Gi"
      volumeMounts:
        - mountPath: /etc
          name: scratch-volume
      env:
        - name: MY_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: MY_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: SCRATCH_VOLUME
          valueFrom:
            fieldRef:
              fieldPath: volume.scratch
        - name: MY_OVERLAY_REQUEST
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: requests.overlay
  restartPolicy: Never
  volumes:
  - name: scratch-volume
    emptyDir: 
      sizeLimit: 10Mi

Do not enable LocalStorageCapacityIsolation feature gate:
Validation failed:

nickren@nickren-ubuntu14:~/test/test$ kubectl create -f downward-localstorage.yaml 
The Pod "dapi-envars-fieldref" is invalid: 
* spec.volumes[0].emptyDir.sizeLimit: Forbidden: SizeLimit field disabled by feature-gate for EmptyDir volumes
* spec.containers[0].env[2].valueFrom.fieldRef: Forbidden: volume.scratch disabled by feature-gate for Downward API
* spec.containers[0].volumeMounts[0].name: Not found: "scratch-volume"

Enable LocalStorageCapacityIsolation :
Pod is created successfully

nickren@nickren-ubuntu14:~/test/test$ kubectl create -f downward-localstorage.yaml 
pod "dapi-envars-fieldref" created
nickren@nickren-ubuntu14:~/test/test$ kubectl describe pods dapi-envars-fieldref
Name:           dapi-envars-fieldref
Namespace:      default
Node:           nickren-ubuntu14/192.168.1.102
Start Time:     Fri, 11 Aug 2017 15:50:51 +0800
Labels:         <none>
Annotations:    <none>
Status:         Running
IP:             172.17.0.2
Containers:
  test-container:
    Container ID:       docker://50e8dda24721426a70be4b23c9842232f5e49fcb9399523a32733e3f43c24c61
    Image:              nginx
    Image ID:           docker://sha256:958a7ae9e56979be256796dabd5845c704f784cd422734184999cf91f24c2547
    Port:               <none>
    Command:
      sh
      -c
    Args:
      while true; do echo -en '\n'; printenv MY_NODE_NAME MY_POD_NAME SCRATCH_VOLUME; sleep 10; done;
    State:              Running
      Started:          Fri, 11 Aug 2017 15:50:52 +0800
    Ready:              True
    Restart Count:      0
    Limits:
      cpu:                              250m
      memory:                           64Mi
      storage.kubernetes.io/overlay:    1Gi
    Requests:
      cpu:                              125m
      memory:                           32Mi
      storage.kubernetes.io/overlay:    500Mi
    Environment:
      MY_NODE_NAME:              (v1:spec.nodeName)
      MY_POD_NAME:              dapi-envars-fieldref (v1:metadata.name)
      SCRATCH_VOLUME:            (v1:volume.scratch)
      MY_OVERLAY_REQUEST:        (requests.overlay)
    Mounts:
      /etc from scratch-volume (rw)
Conditions:
  Type          Status
  Initialized   True 
  Ready         True 
  PodScheduled  True 
Volumes:
  scratch-volume:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
QoS Class:      Burstable
Node-Selectors: <none>
Tolerations:    <none>
Events:
  FirstSeen     LastSeen        Count   From                            SubObjectPath                   Type            Reason                  Message
  ---------     --------        -----   ----                            -------------                   --------        ------                  -------
  3s            3s              1       default-scheduler                                               Normal          Scheduled               Successfully assigned dapi-envars-fieldref to nickren-ubuntu14
  3s            3s              1       kubelet, nickren-ubuntu14                                       Normal          SuccessfulMountVolume   MountVolume.SetUp succeeded for volume "scratch-volume" 
  2s            2s              1       kubelet, nickren-ubuntu14       spec.containers{test-container} Normal          Pulled                  Container image "nginx" already present on machine
  2s            2s              1       kubelet, nickren-ubuntu14       spec.containers{test-container} Normal          Created                 Created container
  2s            2s              1       kubelet, nickren-ubuntu14       spec.containers{test-container} Normal          Started                 Started container
nickren@nickren-ubuntu14:~/test/test$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
50e8dda24721        958a7ae9e569        "sh -c 'while true; d"   6 seconds ago       Up 6 seconds                            k8s_test-container_dapi-envars-fieldref_default_cbe23bbe-7e69-11e7-8231-080027b2eb62_0
6c2eab8e2c05        pause               "/pause"                 7 seconds ago       Up 6 seconds                            k8s_POD_dapi-envars-fieldref_default_cbe23bbe-7e69-11e7-8231-080027b2eb62_0

and I entered the container, found that overlay and scratch are exposed to the container:

nickren@nickren-ubuntu14:~/test/test$ docker exec -it 50e8dda24721 /bin/bash
bash-4.4# env                                                                                                                                                           
SCRATCH_VOLUME=10Mi
HOSTNAME=dapi-envars-fieldref
NJS_VERSION=1.13.1.0.1.10-1~stretch
NGINX_VERSION=1.13.1-1~stretch
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_ADDR=20.1.0.1
MY_POD_NAME=dapi-envars-fieldref
KUBERNETES_PORT=tcp://20.1.0.1:443
PWD=/
HOME=/
MY_OVERLAY_REQUEST=524288000
KUBERNETES_SERVICE_PORT_HTTPS=443
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP=tcp://20.1.0.1:443
MY_NODE_NAME=nickren-ubuntu14
SHLVL=1
KUBERNETES_SERVICE_PORT=443
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
KUBERNETES_SERVICE_HOST=20.1.0.1
_=/usr/bin/env
bash-4.4# 

Here:
SCRATCH_VOLUME=10Mi
...
MY_OVERLAY_REQUEST=524288000

@NickrenREN NickrenREN force-pushed the localstorage-downwardapi branch from 126fe8a to 5fb10e7 Compare August 16, 2017 05:38
@NickrenREN
Copy link
Copy Markdown
Contributor Author

NickrenREN commented Aug 16, 2017

@jingxu97 @ddysher
Since finally decided to manage a single local storage resource(using scratch for now, may change), PR was modified and tested.
pod yaml file:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-envars-fieldref
spec:
  containers:
    - name: test-container
      image: nginx
      imagePullPolicy: IfNotPresent
      command: [ "sh", "-c"]
      args:
      - while true; do
          echo -en '\n';
          printenv MY_SCRATCH_REQUEST MY_SCRATCH_LIMIT;
          sleep 10;
        done;
      resources:
        requests:
          memory: "32Mi"
          cpu: "125m"
          storage.kubernetes.io/scratch: "500Mi"
        limits:
          memory: "64Mi"
          cpu: "250m"
          storage.kubernetes.io/scratch: "1Gi"
      env:
        - name: MY_SCRATCH_REQUEST
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: requests.scratch
        - name: MY_SCRATCH_LIMIT
          valueFrom:
            resourceFieldRef:
              containerName: test-container
              resource: limits.scratch
  restartPolicy: Never

Result:

nickren@nickren-ubuntu14:~/test/test$ kubectl create -f downward-scratch.yaml 
pod "dapi-envars-fieldref" created
nickren@nickren-ubuntu14:~/test/test$ kubeclt get pods
kubeclt: command not found
nickren@nickren-ubuntu14:~/test/test$ kubectl get pods
NAME                   READY     STATUS    RESTARTS   AGE
dapi-envars-fieldref   1/1       Running   0          10s
nickren@nickren-ubuntu14:~/test/test$ kubectl describe pods dapi-envars-fieldref
Name:           dapi-envars-fieldref
Namespace:      default
Node:           nickren-ubuntu14/192.168.1.103
Start Time:     Wed, 16 Aug 2017 14:40:33 +0800
Labels:         <none>
Annotations:    <none>
Status:         Running
IP:             172.17.0.2
Containers:
  test-container:
    Container ID:       docker://d916b229dd9dbc4068a2cbf95018f20b8eb20262f344e97a70f67dea247a3b15
    Image:              nginx
    Image ID:           docker://sha256:958a7ae9e56979be256796dabd5845c704f784cd422734184999cf91f24c2547
    Port:               <none>
    Command:
      sh
      -c
    Args:
      while true; do echo -en '\n'; printenv MY_SCRATCH_REQUEST MY_SCRATCH_LIMIT; sleep 10; done;
    State:              Running
      Started:          Wed, 16 Aug 2017 14:40:34 +0800
    Ready:              True
    Restart Count:      0
    Limits:
      cpu:                              250m
      memory:                           64Mi
      storage.kubernetes.io/scratch:    1Gi
    Requests:
      cpu:                              125m
      memory:                           32Mi
      storage.kubernetes.io/scratch:    500Mi
    Environment:
      MY_SCRATCH_REQUEST:        (requests.scratch)
      MY_SCRATCH_LIMIT:          (limits.scratch)
    Mounts:                     <none>
Conditions:
  Type          Status
  Initialized   True 
  Ready         True 
  PodScheduled  True 
Volumes:        <none>
QoS Class:      Burstable
Node-Selectors: <none>
Tolerations:    <none>
Events:
  FirstSeen     LastSeen        Count   From                            SubObjectPath                   Type            Reason          Message
  ---------     --------        -----   ----                            -------------                   --------        ------          -------
  27s           27s             1       default-scheduler                                               Normal          Scheduled       Successfully assigned dapi-envars-fieldref to nickren-ubuntu14
  27s           27s             1       kubelet, nickren-ubuntu14       spec.containers{test-container} Normal          Pulled          Container image "nginx" already present on machine
  26s           26s             1       kubelet, nickren-ubuntu14       spec.containers{test-container} Normal          Created         Created container
  26s           26s             1       kubelet, nickren-ubuntu14       spec.containers{test-container} Normal          Started         Started container
nickren@nickren-ubuntu14:~/test/test$ docker exec -it d916b229dd9db /bin/bash
root@dapi-envars-fieldref:/# env | grep SCRATCH
MY_SCRATCH_LIMIT=1073741824
MY_SCRATCH_REQUEST=524288000

root@dapi-envars-fieldref:/# exit
exit
nickren@nickren-ubuntu14:~/test/test$ kubectl logs dapi-envars-fieldref
-en 

524288000
1073741824
-en 

524288000
1073741824
-en 

524288000
1073741824
-en 

524288000
1073741824

@jingxu97
Copy link
Copy Markdown
Contributor

lgtm

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 24, 2017
@NickrenREN NickrenREN force-pushed the localstorage-downwardapi branch from 5fb10e7 to df4e71f Compare August 26, 2017 05:07
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 26, 2017
@NickrenREN
Copy link
Copy Markdown
Contributor Author

/retest

@NickrenREN
Copy link
Copy Markdown
Contributor Author

NickrenREN commented Aug 26, 2017

Have done the rebase and changed the local ephemeral storage resource name.

@NickrenREN
Copy link
Copy Markdown
Contributor Author

/assign @thockin

@jingxu97
Copy link
Copy Markdown
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 28, 2017
@thockin
Copy link
Copy Markdown
Member

thockin commented Aug 29, 2017

/approve

@thockin
Copy link
Copy Markdown
Member

thockin commented Aug 29, 2017

/approve no-issue

@k8s-github-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: NickrenREN, jingxu97, thockin

Associated issue requirement bypassed by: thockin

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these OWNERS Files:

You can indicate your approval by writing /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 29, 2017
@NickrenREN
Copy link
Copy Markdown
Contributor Author

/retest

@k8s-github-robot
Copy link
Copy Markdown

Automatic merge from submit-queue (batch tested with PRs 51471, 50561, 50435, 51473, 51436)

@k8s-github-robot k8s-github-robot merged commit 9f6c61b into kubernetes:master Aug 29, 2017
@NickrenREN NickrenREN deleted the localstorage-downwardapi branch August 29, 2017 09:32
@jingxu97
Copy link
Copy Markdown
Contributor

jingxu97 commented Aug 29, 2017

cc @thockin Could you please help approve this PR?

@NickrenREN
Copy link
Copy Markdown
Contributor Author

NickrenREN commented Aug 30, 2017

Thanks @jingxu97 this one has been merged. Maybe you
mean #50757 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants