4月13日
    20:30-21:30
    课时 1
    课外基础
    0.访问Docker 官网关注 Docker安全。
    1.了解当前商业使用的存储类型和方式 。
    2.了解docker数据持久化存储方式和后边讲解k8s的存储方式区别 。
    3.了解几个常用的经典 docker镜像构建方案 。
    4.了解docker安全方案常用的集中方式 。
    课程重点
    通过存储方案的了解常用方式进而在实际的工作中采用相应的存储方式
    数据共享与持久化
    为什么需要数据持久化?
    挂载数据卷
    创建数据卷
    数据卷备份
    数据卷插件介绍
    持久化实践
    实际场景落地介绍和刨析
    Docker最佳实践
    常用命令与实际使用最佳实践
    使用Dockerfile构建镜像
    Docker安全部署实践
    Docker运维实践与技巧

    课后作业
    1 数据持久化的方式
    2 docker save 和 export的区别
    3 docker 镜像分层结构理解
    4 docker 常用镜像构建

    docker import || docker export
    docker load || docker save

    1. [root@master ~]# docker history --no-trunc mysql:5.6.41 | tac | tr -s ' ' | cut -d " " -f 5- | sed 's,^/bin/sh -c #(nop) ,,g' | sed 's,^/bin/sh -c,RUN,g' | sed 's, && ,\n & ,g' | sed 's,\s*[0-9]*[\.]*[0-9]*\s*[kMG]*B\s*$,,g' | head -n -1
    2. ADD file:f8f26d117bc4a9289b7cd7447ca36e1a70b11701c63d949ef35ff9c16e190e50 in /
    3. CMD ["bash"]
    4. RUN groupadd -r mysql
    5. && useradd -r -g mysql mysql
    6. RUN apt-get update
    7. && apt-get install -y --no-install-recommends gnupg dirmngr
    8. && rm -rf /var/lib/apt/lists/*
    9. ENV GOSU_VERSION=1.7
    10. RUN set -x
    11. && apt-get update
    12. && apt-get install -y --no-install-recommends ca-certificates wget
    13. && rm -rf /var/lib/apt/lists/*
    14. && wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture)"
    15. && wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$(dpkg --print-architecture).asc"
    16. && export GNUPGHOME="$(mktemp -d)"
    17. && gpg --keyserver ha.pool.sks-keyservers.net --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4
    18. && gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu
    19. && gpgconf --kill all
    20. && rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc
    21. && chmod +x /usr/local/bin/gosu
    22. && gosu nobody true
    23. && apt-get purge -y --auto-remove ca-certificates wget
    24. RUN mkdir /docker-entrypoint-initdb.d
    25. RUN apt-get update
    26. && apt-get install -y --no-install-recommends pwgen perl
    27. && rm -rf /var/lib/apt/lists/*
    28. RUN set -ex; key='A4A9406876FCBD3C456770C88C718D3B5072E1F5'; export GNUPGHOME="$(mktemp -d)"; gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$key"; gpg --export "$key" > /etc/apt/trusted.gpg.d/mysql.gpg; gpgconf --kill all; rm -rf "$GNUPGHOME"; apt-key list > /dev/null
    29. ENV MYSQL_MAJOR=5.6
    30. ENV MYSQL_VERSION=5.6.41-1debian9
    31. RUN echo "deb http://repo.mysql.com/apt/debian/ stretch mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list
    32. RUN { echo mysql-community-server mysql-community-server/data-dir select ''; echo mysql-community-server mysql-community-server/root-pass password ''; echo mysql-community-server mysql-community-server/re-root-pass password ''; echo mysql-community-server mysql-community-server/remove-test-db select false; } | debconf-set-selections
    33. && apt-get update
    34. && apt-get install -y mysql-server="${MYSQL_VERSION}"
    35. && rm -rf /var/lib/apt/lists/*
    36. && rm -rf /var/lib/mysql
    37. && mkdir -p /var/lib/mysql /var/run/mysqld
    38. && chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
    39. && chmod 777 /var/run/mysqld
    40. && find /etc/mysql/ -name '*.cnf' -print0 | xargs -0 grep -lZE '^(bind-address|log)' | xargs -rt -0 sed -Ei 's/^(bind-address|log)/#&/'
    41. && echo '[mysqld]\nskip-host-cache\nskip-name-resolve' > /etc/mysql/conf.d/docker.cnf
    42. VOLUME [/var/lib/mysql]
    43. COPY file:b79e447a4154d7150da6897e9bfdeac5eef0ebd39bb505803fdb0315c929d983 in /usr/local/bin/
    44. RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
    45. ENTRYPOINT ["docker-entrypoint.sh"]
    46. EXPOSE 3306/tcp
    47. CMD ["mysqld"]
    48. [root@master ~]#
    49. [root@master ~]# sh image.sh nginx
    50. ADD file:d1f1b387a158136fb0f8096c8a8ecf5fc146be4e85c1c3c345d44c927692723a in /
    51. CMD ["bash"]
    52. LABEL maintainer=NGINX Docker Maintainers <docker-maint@nginx.com>
    53. ENV NGINX_VERSION=1.17.9
    54. ENV NJS_VERSION=0.3.9
    55. ENV PKG_RELEASE=1~buster
    56. RUN set -x
    57. && addgroup --system --gid 101 nginx
    58. && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx
    59. && apt-get update
    60. && apt-get install --no-install-recommends --no-install-suggests -y gnupg1 ca-certificates
    61. && NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; found=''; for server in ha.pool.sks-keyservers.net hkp://keyserver.ubuntu.com:80 hkp://p80.pool.sks-keyservers.net:80 pgp.mit.edu ; do echo "Fetching GPG key $NGINX_GPGKEY from $server"; apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY"
    62. && found=yes
    63. && break; done; test -z "$found"
    64. && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY"
    65. && exit 1; apt-get remove --purge --auto-remove -y gnupg1
    66. && rm -rf /var/lib/apt/lists/*
    67. && dpkgArch="$(dpkg --print-architecture)"
    68. && nginxPackages=" nginx=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-xslt=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-geoip=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-image-filter=${NGINX_VERSION}-${PKG_RELEASE} nginx-module-njs=${NGINX_VERSION}.${NJS_VERSION}-${PKG_RELEASE} "
    69. && case "$dpkgArch" in amd64|i386) echo "deb https://nginx.org/packages/mainline/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list
    70. && apt-get update ;; *) echo "deb-src https://nginx.org/packages/mainline/debian/ buster nginx" >> /etc/apt/sources.list.d/nginx.list
    71. && tempDir="$(mktemp -d)"
    72. && chmod 777 "$tempDir"
    73. && savedAptMark="$(apt-mark showmanual)"
    74. && apt-get update
    75. && apt-get build-dep -y $nginxPackages
    76. && ( cd "$tempDir"
    77. && DEB_BUILD_OPTIONS="nocheck parallel=$(nproc)" apt-get source --compile $nginxPackages )
    78. && apt-mark showmanual | xargs apt-mark auto > /dev/null
    79. && { [ -z "$savedAptMark" ] || apt-mark manual $savedAptMark; }
    80. && ls -lAFh "$tempDir"
    81. && ( cd "$tempDir"
    82. && dpkg-scanpackages . > Packages )
    83. && grep '^Package: ' "$tempDir/Packages"
    84. && echo "deb [ trusted=yes ] file://$tempDir ./" > /etc/apt/sources.list.d/temp.list
    85. && apt-get -o Acquire::GzipIndexes=false update ;; esac
    86. && apt-get install --no-install-recommends --no-install-suggests -y $nginxPackages gettext-base
    87. && apt-get remove --purge --auto-remove -y ca-certificates
    88. && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx.list
    89. && if [ -n "$tempDir" ]; then apt-get purge -y --auto-remove
    90. && rm -rf "$tempDir" /etc/apt/sources.list.d/temp.list; fi
    91. RUN ln -sf /dev/stdout /var/log/nginx/access.log
    92. && ln -sf /dev/stderr /var/log/nginx/error.log
    93. EXPOSE 80
    94. STOPSIGNAL SIGTERM
    95. CMD ["nginx" "-g" "daemon off;"]
    96. [root@master ~]#
    97. [root@master ~]# cat image.sh
    98. #! /bin/bash
    99. docker history --no-trunc $1 | tac | tr -s ' ' | cut -d " " -f 5- | sed 's,^/bin/sh -c #(nop) ,,g' | sed 's,^/bin/sh -c,RUN,g' | sed 's, && ,\n & ,g' | sed 's,\s*[0-9]*[\.]*[0-9]*\s*[kMG]*B\s*$,,g' | head -n -1
    100. [root@master ~]#
    1. [root@riyimei home]# git clone https://github.com/lukapeschke/dockerfile-from-image.git
    2. Cloning into 'dockerfile-from-image'...
    3. remote: Enumerating objects: 36, done.
    4. remote: Total 36 (delta 0), reused 0 (delta 0), pack-reused 36
    5. Unpacking objects: 100% (36/36), done.
    6. [root@riyimei home]#
    7. [root@riyimei home]# ll
    8. total 0
    9. drwxr-xr-x 4 root root 33 Apr 13 14:40 docker
    10. drwxr-xr-x 3 root root 74 Apr 13 20:48 dockerfile-from-image
    11. drwxr-xr-x 2 root root 24 Apr 3 14:13 k8s
    12. drwxr-xr-x 2 root root 6 Apr 13 15:23 mindoc
    13. drwx------ 2 rancher rancher 62 Apr 3 14:13 rancher
    14. [root@riyimei home]# cd dockerfile-from-image/
    15. [root@riyimei dockerfile-from-image]#
    16. [root@riyimei dockerfile-from-image]# ll
    17. total 12
    18. -rw-r--r-- 1 root root 294 Apr 13 20:48 Dockerfile
    19. -rwxr-xr-x 1 root root 1496 Apr 13 20:48 entrypoint.py
    20. -rw-r--r-- 1 root root 2587 Apr 13 20:48 README.md
    21. [root@riyimei dockerfile-from-image]#
    22. [root@riyimei dockerfile-from-image]# docker build -t lukapeschke/dfa .
    23. Sending build context to Docker daemon 108.5kB
    24. Step 1/4 : FROM alpine
    25. latest: Pulling from library/alpine
    26. aad63a933944: Pull complete
    27. Digest: sha256:b276d875eeed9c7d3f1cfa7edb06b22ed22b14219a7d67c52c56612330348239
    28. Status: Downloaded newer image for alpine:latest
    29. ---> a187dde48cd2
    30. Step 2/4 : RUN apk add --update python3 wget && wget -O - --no-check-certificate https://bootstrap.pypa.io/get-pip.py | python3 && apk del wget && pip3 install -U docker-py && yes | pip3 uninstall pip
    31. ---> Running in 983362554de9
    32. fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
    33. fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
    34. (1/11) Installing libbz2 (1.0.8-r1)
    35. (2/11) Installing expat (2.2.9-r1)
    36. (3/11) Installing libffi (3.2.1-r6)
    37. (4/11) Installing gdbm (1.13-r1)
    38. (5/11) Installing xz-libs (5.2.4-r0)
    39. (6/11) Installing ncurses-terminfo-base (6.1_p20200118-r3)
    40. (7/11) Installing ncurses-libs (6.1_p20200118-r3)
    41. (8/11) Installing readline (8.0.1-r0)
    42. (9/11) Installing sqlite-libs (3.30.1-r1)
    43. (10/11) Installing python3 (3.8.2-r0)
    44. (11/11) Installing wget (1.20.3-r0)
    45. Executing busybox-1.31.1-r9.trigger
    46. OK: 65 MiB in 25 packages
    47. --2020-04-13 13:08:11-- https://bootstrap.pypa.io/get-pip.py
    48. Resolving bootstrap.pypa.io... 151.101.228.175, 2a04:4e42:36::175
    49. Connecting to bootstrap.pypa.io|151.101.228.175|:443... connected.
    50. HTTP request sent, awaiting response... 200 OK
    51. Length: 1807342 (1.7M) [text/x-python]
    52. Saving to: 'STDOUT'
    53. 0K .......... .......... .......... .......... .......... 2% 44.5K 39s
    54. 50K .......... .......... .......... .......... .......... 5% 26.5K 50s
    55. 100K .......... .......... .......... .......... .......... 8% 16.6K 65s
    56. 150K .......... .......... .......... .......... .......... 11% 30.1K 60s
    57. 200K .......... .......... .......... .......... .......... 14% 19.9K 62s
    58. 250K .......... .......... .......... .......... .......... 16% 44.0K 55s
    59. 300K .......... .......... .......... .......... .......... 19% 11.8K 63s
    60. 350K .......... .......... .......... .......... .......... 22% 7.96K 75s
    61. 400K .......... .......... .......... .......... .......... 25% 12.8K 75s
    62. 450K .......... .......... .......... .......... .......... 28% 10.2K 78s
    63. 500K .......... .......... .......... .......... .......... 31% 10.1K 79s
    64. 550K .......... .......... .......... .......... .......... 33% 12.8K 77s
    65. 600K .......... .......... .......... .......... .......... 36% 18.5K 72s
    66. 650K .......... .......... .......... .......... .......... 39% 20.1K 68s
    67. 700K .......... .......... .......... .......... .......... 42% 12.2K 66s
    68. 750K .......... .......... .......... .......... .......... 45% 8.73K 66s
    69. 800K .......... .......... .......... .......... .......... 48% 9.89K 64s
    70. 850K .......... .......... .......... .......... .......... 50% 18.2K 60s
    71. 900K .......... .......... .......... .......... .......... 53% 12.9K 57s
    72. 950K .......... .......... .......... .......... .......... 56% 11.7K 54s
    73. 1000K .......... .......... .......... .......... .......... 59% 17.3K 50s
    74. 1050K .......... .......... .......... .......... .......... 62% 9.11K 48s
    75. 1100K .......... .......... .......... .......... .......... 65% 20.9K 43s
    76. 1150K .......... .......... .......... .......... .......... 67% 13.9K 40s
    77. 1200K .......... .......... .......... .......... .......... 70% 12.3K 37s
    78. 1250K .......... .......... .......... .......... .......... 73% 10.9K 33s
    79. 1300K .......... .......... .......... .......... .......... 76% 10.2K 30s
    80. 1350K .......... .......... .......... .......... .......... 79% 19.4K 26s
    81. 1400K .......... .......... .......... .......... .......... 82% 17.6K 23s
    82. 1450K .......... .......... .......... .......... .......... 84% 20.7K 19s
    83. 1500K .......... .......... .......... .......... .......... 87% 14.3K 15s
    84. 1550K .......... .......... .......... .......... .......... 90% 7.73K 12s
    85. 1600K .......... .......... .......... .......... .......... 93% 17.7K 8s
    86. 1650K .......... .......... .......... .......... .......... 96% 11.0K 5s
    87. 1700K .......... .......... .......... .......... .......... 99% 14.4K 1s
    88. 1750K .......... .... 100% 17.3K=2m8s
    89. 2020-04-13 13:10:21 (13.8 KB/s) - written to stdout [1807342/1807342]
    90. Collecting pip
    91. Downloading pip-20.0.2-py2.py3-none-any.whl (1.4 MB)
    92. Collecting wheel
    93. Downloading wheel-0.34.2-py2.py3-none-any.whl (26 kB)
    94. Installing collected packages: pip, wheel
    95. Attempting uninstall: pip
    96. Found existing installation: pip 19.2.3
    97. Uninstalling pip-19.2.3:
    98. Successfully uninstalled pip-19.2.3
    99. Successfully installed pip-20.0.2 wheel-0.34.2
    100. (1/1) Purging wget (1.20.3-r0)
    101. Executing busybox-1.31.1-r9.trigger
    102. OK: 64 MiB in 24 packages
    103. Collecting docker-py
    104. Downloading docker_py-1.10.6-py2.py3-none-any.whl (50 kB)
    105. Collecting six>=1.4.0
    106. Downloading six-1.14.0-py2.py3-none-any.whl (10 kB)
    107. Collecting requests!=2.11.0,>=2.5.2
    108. Downloading requests-2.23.0-py2.py3-none-any.whl (58 kB)
    109. Collecting websocket-client>=0.32.0
    110. Downloading websocket_client-0.57.0-py2.py3-none-any.whl (200 kB)
    111. Collecting docker-pycreds>=0.2.1
    112. Downloading docker_pycreds-0.4.0-py2.py3-none-any.whl (9.0 kB)
    113. Collecting idna<3,>=2.5
    114. Downloading idna-2.9-py2.py3-none-any.whl (58 kB)
    115. Collecting certifi>=2017.4.17
    116. Downloading certifi-2020.4.5.1-py2.py3-none-any.whl (157 kB)
    117. Collecting chardet<4,>=3.0.2
    118. Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB)
    119. Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
    120. Downloading urllib3-1.25.8-py2.py3-none-any.whl (125 kB)
    121. Installing collected packages: six, idna, certifi, chardet, urllib3, requests, websocket-client, docker-pycreds, docker-py
    122. Successfully installed certifi-2020.4.5.1 chardet-3.0.4 docker-py-1.10.6 docker-pycreds-0.4.0 idna-2.9 requests-2.23.0 six-1.14.0 urllib3-1.25.8 websocket-client-0.57.0
    123. Found existing installation: pip 20.0.2
    124. Uninstalling pip-20.0.2:
    125. Would remove:
    126. /usr/bin/pip
    127. /usr/bin/pip3
    128. /usr/bin/pip3.8
    129. /usr/lib/python3.8/site-packages/pip-20.0.2.dist-info/*
    130. /usr/lib/python3.8/site-packages/pip/*
    131. Proceed (y/n)? Successfully uninstalled pip-20.0.2
    132. Removing intermediate container 983362554de9
    133. ---> b06b75c6e0e6
    134. Step 3/4 : COPY entrypoint.py /root
    135. ---> 3027eb4f7f60
    136. Step 4/4 : ENTRYPOINT ["/root/entrypoint.py"]
    137. ---> Running in be69ded401bd
    138. Removing intermediate container be69ded401bd
    139. ---> a6576fa3846e
    140. Successfully built a6576fa3846e
    141. Successfully tagged lukapeschke/dfa:latest
    142. [root@riyimei dockerfile-from-image]# docker image ls
    143. REPOSITORY TAG IMAGE ID CREATED SIZE
    144. lukapeschke/dfa latest a6576fa3846e About a minute ago 58.5MB
    145. local/c7-systemd-httpd latest 047bf64886a3 7 hours ago 260MB
    146. local/c7-systemd latest 900b71d7e1bb 7 hours ago 203MB
    147. postgres latest 9907cacf0c01 13 days ago 314MB
    148. nginx latest ed21b7a8aee9 13 days ago 127MB
    149. alpine latest a187dde48cd2 2 weeks ago 5.6MB
    150. ubuntu latest 4e5021d210f6 3 weeks ago 64.2MB
    151. busybox latest 83aa35aa1c79 4 weeks ago 1.22MB
    152. centos latest 470671670cac 2 months ago 237MB
    153. centos 7 5e35e350aded 5 months ago 203MB
    154. jackdanger/dockerfile-from-image latest 12c48318d21a 14 months ago 148MB
    155. chenlicn163/ubuntu-stress latest dc79bd8927d6 15 months ago 112MB
    156. joedval/stress latest 89e5b79daa74 4 years ago 215MB
    157. liweiming0611/stress latest 89e5b79daa74 4 years ago 215MB
    158. [root@riyimei dockerfile-from-image]# docker run --rm -v '/var/run/docker.sock:/var/run/docker.sock' lukapeschke/dfa 4e5021d210f6
    159. FROM ubuntu:latest
    160. ADD file:594fa35cf803361e69d817fc867b6a4069c064ffd20ed50caf42ad9bb11ca999 in /
    161. RUN /bin/sh -c [ -z "$(apt-get indextargets)" ]
    162. RUN /bin/sh -c set -xe \
    163. && echo '#!/bin/sh' > /usr/sbin/policy-rc.d \
    164. && echo 'exit 101' >> /usr/sbin/policy-rc.d \
    165. && chmod +x /usr/sbin/policy-rc.d \
    166. && dpkg-divert --local --rename --add /sbin/initctl \
    167. && cp -a /usr/sbin/policy-rc.d /sbin/initctl \
    168. && sed -i 's/^exit.*/exit 0/' /sbin/initctl \
    169. && echo 'force-unsafe-io' > /etc/dpkg/dpkg.cfg.d/docker-apt-speedup \
    170. && echo 'DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' > /etc/apt/apt.conf.d/docker-clean \
    171. && echo 'APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };' >> /etc/apt/apt.conf.d/docker-clean \
    172. && echo 'Dir::Cache::pkgcache ""; Dir::Cache::srcpkgcache "";' >> /etc/apt/apt.conf.d/docker-clean \
    173. && echo 'Acquire::Languages "none";' > /etc/apt/apt.conf.d/docker-no-languages \
    174. && echo 'Acquire::GzipIndexes "true"; Acquire::CompressionTypes::Order:: "gz";' > /etc/apt/apt.conf.d/docker-gzip-indexes \
    175. && echo 'Apt::AutoRemove::SuggestsImportant "false";' > /etc/apt/apt.conf.d/docker-autoremove-suggests
    176. RUN /bin/sh -c mkdir -p /run/systemd \
    177. && echo 'docker' > /run/systemd/container
    178. CMD ["/bin/bash"]
    179. [root@riyimei dockerfile-from-image]#
    1. [root@riyimei httpd]# docker run --rm busybox sh -c 'ulimit -S -a | grep stack && ulimit -H -a | grep stack'
    2. stack size (kb) (-s) 8192
    3. stack size (kb) (-s) unlimited
    4. [root@riyimei httpd]# ulimit -S -a
    5. core file size (blocks, -c) unlimited
    6. data seg size (kbytes, -d) unlimited
    7. scheduling priority (-e) 0
    8. file size (blocks, -f) unlimited
    9. pending signals (-i) 3624
    10. max locked memory (kbytes, -l) 64
    11. max memory size (kbytes, -m) unlimited
    12. open files (-n) 1000000
    13. pipe size (512 bytes, -p) 8
    14. POSIX message queues (bytes, -q) 819200
    15. real-time priority (-r) 0
    16. stack size (kbytes, -s) 10240
    17. cpu time (seconds, -t) unlimited
    18. max user processes (-u) 3624
    19. virtual memory (kbytes, -v) unlimited
    20. file locks (-x) unlimited
    21. [root@riyimei httpd]#
    1. initContainers:
    2. - name: increase-vm-max-map-count
    3. image: busybox
    4. imagePullPolicy: IfNotPresent
    5. command: ["sysctl", "-w", "vm.max_map_count=1048575"]
    6. securityContext:
    7. privileged: true
    8. - name: increase-ulimit
    9. image: busybox
    10. command: [ "sh","-c","ulimit -l unlimited" ]
    11. securityContext:
    12. privileged: true

    https://raw.githubusercontent.com/strapdata/kubernetes-elassandra/master/elassandra-statefulset.yaml

    1. ---
    2. apiVersion: "apps/v1beta1"
    3. kind: StatefulSet
    4. metadata:
    5. name: elassandra
    6. spec:
    7. serviceName: elassandra
    8. replicas: 3
    9. updateStrategy:
    10. type: RollingUpdate
    11. template:
    12. metadata:
    13. labels:
    14. app: elassandra
    15. spec:
    16. # See https://pracucci.com/graceful-shutdown-of-kubernetes-pods.html
    17. terminationGracePeriodSeconds: 300
    18. securityContext:
    19. # allows read/write access for mounted volumes
    20. # by users that belong to a group with gid: 999
    21. fsGroup: 999
    22. initContainers:
    23. - name: increase-vm-max-map-count
    24. image: busybox
    25. imagePullPolicy: IfNotPresent
    26. command: ["sysctl", "-w", "vm.max_map_count=1048575"]
    27. securityContext:
    28. privileged: true
    29. - name: increase-ulimit
    30. image: busybox
    31. command: [ "sh","-c","ulimit -l unlimited" ]
    32. securityContext:
    33. privileged: true
    34. containers:
    35. - name: elassandra
    36. image: strapdata/elassandra:5.5.0.22-rc1
    37. imagePullPolicy: Always
    38. securityContext:
    39. privileged: false
    40. # applying fix in: https://github.com/kubernetes/kubernetes/issues/3595#issuecomment-287692878
    41. # https://docs.docker.com/engine/reference/run/#operator-exclusive-options
    42. capabilities:
    43. add: ["IPC_LOCK", "SYS_RESOURCE"]
    44. livenessProbe:
    45. tcpSocket:
    46. port: 7000
    47. initialDelaySeconds: 15
    48. periodSeconds: 5
    49. readinessProbe:
    50. exec:
    51. command: [ "/bin/bash", "-c", "/ready-probe.sh" ]
    52. initialDelaySeconds: 15
    53. timeoutSeconds: 5
    54. lifecycle:
    55. preStop:
    56. exec:
    57. command: ["/bin/sh", "-c", "exec nodetool drain"]
    58. ports:
    59. - containerPort: 7000
    60. name: intra-node
    61. - containerPort: 7001
    62. name: tls-intra-node
    63. - containerPort: 7199
    64. name: jmx
    65. - containerPort: 9042
    66. name: cql
    67. - containerPort: 9200
    68. name: http
    69. protocol: TCP
    70. - containerPort: 9300
    71. name: transport
    72. protocol: TCP
    73. env:
    74. # environment variables to be directly refrenced from the configuration
    75. - name: NAMESPACE
    76. valueFrom:
    77. fieldRef:
    78. fieldPath: metadata.namespace
    79. - name: POD_NAME
    80. valueFrom:
    81. fieldRef:
    82. fieldPath: metadata.name
    83. - name: POD_IP
    84. valueFrom:
    85. fieldRef:
    86. fieldPath: status.podIP
    87. - name: CASSANDRA_SEEDS
    88. value: elassandra-0.elassandra.default.svc.cluster.local
    89. - name: MAX_HEAP_SIZE
    90. value: 2048M
    91. - name: HEAP_NEWSIZE
    92. value: 512M
    93. - name: CASSANDRA_CLUSTER_NAME
    94. value: "Cassandra"
    95. - name: CASSANDRA_DC
    96. value: "DC1"
    97. - name: CASSANDRA_RACK
    98. value: "r1"
    99. - name: CASSANDRA_ENDPOINT_SNITCH
    100. value: GossipingPropertyFileSnitch
    101. # - name: CASSANDRA_DAEMON
    102. # value: "org.apache.cassandra.service.CassandraDaemon"
    103. # logging variables
    104. - name: LOGBACK_org_elassandra_discovery
    105. value: DEBUG
    106. volumeMounts:
    107. - name: elassandra-data
    108. mountPath: /var/lib/cassandra
    109. volumeClaimTemplates:
    110. - metadata:
    111. name: elassandra-data
    112. spec:
    113. accessModes: ["ReadWriteOnce"]
    114. # Define your own storageClassName if needed.
    115. storageClassName: managed-premium
    116. resources:
    117. requests:
    118. storage: 16Gi