7月 282020
 

CentOS 8

编译报错(提示为nghttp2版本太旧)

[root@test httpd-2.4.43]# ./configure --enable-http2

checking for nghttp2... checking for user-provided nghttp2 base directory... none
checking for pkg-config along ... checking for nghttp2 version >= 1.2.1... FAILED
configure: WARNING: nghttp2 version is too old

启用仅CentOS 8支持的Power Tools软件源仓库

可供 CentOS 使用的软件库
https://wiki.centos.org/zh/AdditionalResources/Repositories

PowerTools —— 只供 CentOS8 使用,PowerTools 软件库提供了大量开发者用的工具。缺省是停用的。

[root@test httpd-2.4.43]# dnf config-manager --set-enabled PowerTools
[root@test httpd-2.4.43]# dnf makecache
CentOS-8 - AppStream                                           9.6 kB/s | 4.3 kB     00:00
CentOS-8 - Base                                                8.6 kB/s | 3.9 kB     00:00
CentOS-8 - Extras                                              4.4 kB/s | 1.5 kB     00:00
CentOS-8 - PowerTools                                          1.7 MB/s | 1.9 MB     00:01
Extra Packages for Enterprise Linux Modular 8 - x86_64          57 kB/s |  18 kB     00:00
Extra Packages for Enterprise Linux 8 - x86_64                  58 kB/s |  18 kB     00:00
Metadata cache created.
[root@test httpd-2.4.43]#

安装开发库

[root@test httpd-2.4.43]# dnf -y install libnghttp2-devel

===============================================================================================
 Package                   Architecture    Version                   Repository           Size
===============================================================================================
Installing:
 libnghttp2-devel          x86_64          1.33.0-3.el8_2.1          PowerTools           60 k

Transaction Summary
===============================================================================================
Install  1 Package

重新编译

[root@test httpd-2.4.43]# ./configure --enable-http2

checking whether to enable mod_http2... checking dependencies
checking for OpenSSL... (cached) yes
  setting MOD_LDFLAGS to "-lssl -lcrypto    -lpthread -ldl"
  setting MOD_CFLAGS to ""
  setting MOD_CPPFLAGS to "-DH2_OPENSSL"
checking for nghttp2... checking for user-provided nghttp2 base directory... none
checking for pkg-config along ...   setting MOD_CFLAGS to ""
checking for nghttp2 version >= 1.2.1... OK
  adding "-lnghttp2" to MOD_LDFLAGS
  setting LIBS to "-lnghttp2    -lpthread -ldl"
checking nghttp2/nghttp2.h usability... yes
checking nghttp2/nghttp2.h presence... yes
checking for nghttp2/nghttp2.h... yes
checking for nghttp2_session_server_new2... yes
checking for nghttp2_stream_get_weight... yes
checking for nghttp2_session_change_stream_priority... yes
  adding "-DH2_NG2_CHANGE_PRIO" to MOD_CPPFLAGS
checking for nghttp2_session_callbacks_set_on_invalid_header_callback... yes
  adding "-DH2_NG2_INVALID_HEADER_CB" to MOD_CPPFLAGS
checking for nghttp2_session_get_stream_local_window_size... yes
  adding "-DH2_NG2_LOCAL_WIN_SIZE" to MOD_CPPFLAGS
yes
  setting MOD_HTTP2_LDADD to "-export-symbols-regex http2_module"
7月 012020
 

查看系统时间日期配置

[centos@dev ~]$ sudo timedatectl
[sudo] password for centos:
               Local time: Wed 2020-07-01 09:21:55 UTC
           Universal time: Wed 2020-07-01 09:21:55 UTC
                 RTC time: Wed 2020-07-01 09:21:55
                Time zone: UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[centos@dev ~]$
[centos@dev ~]$ sudo timedatectl --help
timedatectl [OPTIONS...] COMMAND ...

Query or change system time and date settings.

  -h --help                Show this help message
     --version             Show package version
     --no-pager            Do not pipe output into a pager
     --no-ask-password     Do not prompt for password
  -H --host=[USER@]HOST    Operate on remote host
  -M --machine=CONTAINER   Operate on local container
     --adjust-system-clock Adjust system clock when changing local RTC mode
     --monitor             Monitor status of systemd-timesyncd
  -p --property=NAME       Show only properties by this name
  -a --all                 Show all properties, including empty ones
     --value               When showing properties, only print the value

Commands:
  status                   Show current time settings
  show                     Show properties of systemd-timedated
  set-time TIME            Set system time
  set-timezone ZONE        Set system time zone
  list-timezones           Show known time zones
  set-local-rtc BOOL       Control whether RTC is in local time
  set-ntp BOOL             Enable or disable network time synchronization

systemd-timesyncd Commands:
  timesync-status          Show status of systemd-timesyncd
  show-timesync            Show properties of systemd-timesyncd
[centos@dev ~]$

修改系统时区

[centos@dev ~]$ sudo timedatectl set-timezone Asia/Hong_Kong
[centos@dev ~]$ date
Wed Jul  1 17:22:59 HKT 2020
[centos@dev ~]$
[centos@dev ~]$ sudo timedatectl
               Local time: Wed 2020-07-01 17:24:20 HKT
           Universal time: Wed 2020-07-01 09:24:20 UTC
                 RTC time: Wed 2020-07-01 09:24:20
                Time zone: Asia/Hong_Kong (HKT, +0800)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
[centos@dev ~]$
5月 132020
 

练习代码1及注释

# -*- coding: utf-8 -*-
print "Hello World!"
print "Hello Again"
print "I like typing this."
print "This is fun."
print 'Yay! Printing.'
print "I'd much rather you 'not'."
print 'I "said" do not touch this.'
# #号用来注释
# 使用Unicode UTF-8编码以避免乱码

练习代码2及注释

# -*- coding: utf-8 -*-
# A comment, this is so you can read your program later.
# Anything after the # is ignored by python.

print "I could have code like this." # and the comment after is ignored

# You can also use a commnet to "disable" or comment out a piece of code:
# print "This won't run."

print "This will run."
# 注释可以是对某行代码的自然语言描述也可以用作临时禁用该行代码
# 注释符的英文名称为octothorepe或者pound character
# 引号中的#号作为字符串中的一个普通字符

练习代码3及注释

# -*- coding: utf-8 -*-
print "I will now count my chickens:"

print "Hens", 25 + 30 / 6
print "Roosters", 100 - 25 * 3 % 4

print "Now I will count the eggs:"

print 3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6

print "is it true that 3 + 2 < 5 - 7?"

print 3 + 2 < 5 - 7

print "What is 3 + 2?", 3 + 2
print "What is 5 - 7?", 5 - 7

print "Oh, that's why it's False."

print "How about some more."

print "Is it greater?", 5 > -2
print "Is it greater or equal?", 5 >= -2
print "is it less or equal?", 5 <= -2
# 百分号%表示求余数,75除4得18余3
# 运算优先级为括号,指数,乘,除,加,减
# 1/4运算结果舍去了小数部分
5月 062020
 
#!/bin/bash
#

# 禁用SELINUX设置
setenforce 0;
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config;
# 加载内核模块及修改内核参数
cat > /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF
modprobe overlay;
modprobe br_netfilter;
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
sysctl --system;
# 准备容器运行环境
yum makecache;
yum install -y yum-utils;
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo;
yum install -y docker-ce docker-ce-cli containerd.io;
containerd config default > /etc/containerd/config.toml;
#
mkdir /etc/docker;
cat <<EOF > /etc/docker/daemon.json
{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  },
  "storage-driver": "overlay2",
  "storage-opts": [
    "overlay2.override_kernel_check=true"
  ]
}
EOF
#
systemctl daemon-reload;
systemctl enable docker;
systemctl restart docker;
# 准备K8S运行环境(指定组件版本)
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOF
#
yum install -y kubectl-1.16.9 kubelet-1.16.9 kubeadm-1.16.9;
systemctl enable kubelet;

Kubernetes 1.16.9 当前支持的经验证的Docker CE版本为18.09

[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 19.03.8. Latest validated version: 18.09

查看Docker CE YUM仓库当前可用版本(18.09.9)

[root@k8s-01 ~]# yum list docker-ce --showduplicates | sort -r
 * updates: mirrors.sonic.net
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
 * extras: mirror.keystealth.org
docker-ce.x86_64            3:19.03.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.8-3.el7                    @docker-ce-stable
docker-ce.x86_64            3:19.03.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:19.03.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.9-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.8-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.7-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.6-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.5-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.4-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.3-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.2-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.1-3.el7                    docker-ce-stable 
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.3.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.2.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.12.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.09.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.06.0.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.3.ce-1.el7                   docker-ce-stable 
docker-ce.x86_64            17.03.2.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.1.ce-1.el7.centos            docker-ce-stable 
docker-ce.x86_64            17.03.0.ce-1.el7.centos            docker-ce-stable 
 * base: sjc.edge.kernel.org
Available Packages
[root@k8s-01 ~]#
4月 292020
 
[root@k8s01 ~]# yum list kubectl --showduplicates|grep kubectl.x86_64
kubectl.x86_64                       1.18.2-0                        @kubernetes
kubectl.x86_64                       1.5.4-0                         kubernetes 
kubectl.x86_64                       1.6.0-0                         kubernetes 
kubectl.x86_64                       1.6.1-0                         kubernetes 
kubectl.x86_64                       1.6.2-0                         kubernetes 
kubectl.x86_64                       1.6.3-0                         kubernetes 
kubectl.x86_64                       1.6.4-0                         kubernetes 
kubectl.x86_64                       1.6.5-0                         kubernetes 
kubectl.x86_64                       1.6.6-0                         kubernetes 
kubectl.x86_64                       1.6.7-0                         kubernetes 
kubectl.x86_64                       1.6.8-0                         kubernetes 
kubectl.x86_64                       1.6.9-0                         kubernetes 
kubectl.x86_64                       1.6.10-0                        kubernetes 
kubectl.x86_64                       1.6.11-0                        kubernetes 
kubectl.x86_64                       1.6.12-0                        kubernetes 
kubectl.x86_64                       1.6.13-0                        kubernetes 
kubectl.x86_64                       1.7.0-0                         kubernetes 
kubectl.x86_64                       1.7.1-0                         kubernetes 
kubectl.x86_64                       1.7.2-0                         kubernetes 
kubectl.x86_64                       1.7.3-1                         kubernetes 
kubectl.x86_64                       1.7.4-0                         kubernetes 
kubectl.x86_64                       1.7.5-0                         kubernetes 
kubectl.x86_64                       1.7.6-1                         kubernetes 
kubectl.x86_64                       1.7.7-1                         kubernetes 
kubectl.x86_64                       1.7.8-1                         kubernetes 
kubectl.x86_64                       1.7.9-0                         kubernetes 
kubectl.x86_64                       1.7.10-0                        kubernetes 
kubectl.x86_64                       1.7.11-0                        kubernetes 
kubectl.x86_64                       1.7.14-0                        kubernetes 
kubectl.x86_64                       1.7.15-0                        kubernetes 
kubectl.x86_64                       1.7.16-0                        kubernetes 
kubectl.x86_64                       1.8.0-0                         kubernetes 
kubectl.x86_64                       1.8.1-0                         kubernetes 
kubectl.x86_64                       1.8.2-0                         kubernetes 
kubectl.x86_64                       1.8.3-0                         kubernetes 
kubectl.x86_64                       1.8.4-0                         kubernetes 
kubectl.x86_64                       1.8.5-0                         kubernetes 
kubectl.x86_64                       1.8.6-0                         kubernetes 
kubectl.x86_64                       1.8.7-0                         kubernetes 
kubectl.x86_64                       1.8.8-0                         kubernetes 
kubectl.x86_64                       1.8.9-0                         kubernetes 
kubectl.x86_64                       1.8.10-0                        kubernetes 
kubectl.x86_64                       1.8.11-0                        kubernetes 
kubectl.x86_64                       1.8.12-0                        kubernetes 
kubectl.x86_64                       1.8.13-0                        kubernetes 
kubectl.x86_64                       1.8.14-0                        kubernetes 
kubectl.x86_64                       1.8.15-0                        kubernetes 
kubectl.x86_64                       1.9.0-0                         kubernetes 
kubectl.x86_64                       1.9.1-0                         kubernetes 
kubectl.x86_64                       1.9.2-0                         kubernetes 
kubectl.x86_64                       1.9.3-0                         kubernetes 
kubectl.x86_64                       1.9.4-0                         kubernetes 
kubectl.x86_64                       1.9.5-0                         kubernetes 
kubectl.x86_64                       1.9.6-0                         kubernetes 
kubectl.x86_64                       1.9.7-0                         kubernetes 
kubectl.x86_64                       1.9.8-0                         kubernetes 
kubectl.x86_64                       1.9.9-0                         kubernetes 
kubectl.x86_64                       1.9.10-0                        kubernetes 
kubectl.x86_64                       1.9.11-0                        kubernetes 
kubectl.x86_64                       1.10.0-0                        kubernetes 
kubectl.x86_64                       1.10.1-0                        kubernetes 
kubectl.x86_64                       1.10.2-0                        kubernetes 
kubectl.x86_64                       1.10.3-0                        kubernetes 
kubectl.x86_64                       1.10.4-0                        kubernetes 
kubectl.x86_64                       1.10.5-0                        kubernetes 
kubectl.x86_64                       1.10.6-0                        kubernetes 
kubectl.x86_64                       1.10.7-0                        kubernetes 
kubectl.x86_64                       1.10.8-0                        kubernetes 
kubectl.x86_64                       1.10.9-0                        kubernetes 
kubectl.x86_64                       1.10.10-0                       kubernetes 
kubectl.x86_64                       1.10.11-0                       kubernetes 
kubectl.x86_64                       1.10.12-0                       kubernetes 
kubectl.x86_64                       1.10.13-0                       kubernetes 
kubectl.x86_64                       1.11.0-0                        kubernetes 
kubectl.x86_64                       1.11.1-0                        kubernetes 
kubectl.x86_64                       1.11.2-0                        kubernetes 
kubectl.x86_64                       1.11.3-0                        kubernetes 
kubectl.x86_64                       1.11.4-0                        kubernetes 
kubectl.x86_64                       1.11.5-0                        kubernetes 
kubectl.x86_64                       1.11.6-0                        kubernetes 
kubectl.x86_64                       1.11.7-0                        kubernetes 
kubectl.x86_64                       1.11.8-0                        kubernetes 
kubectl.x86_64                       1.11.9-0                        kubernetes 
kubectl.x86_64                       1.11.10-0                       kubernetes 
kubectl.x86_64                       1.12.0-0                        kubernetes 
kubectl.x86_64                       1.12.1-0                        kubernetes 
kubectl.x86_64                       1.12.2-0                        kubernetes 
kubectl.x86_64                       1.12.3-0                        kubernetes 
kubectl.x86_64                       1.12.4-0                        kubernetes 
kubectl.x86_64                       1.12.5-0                        kubernetes 
kubectl.x86_64                       1.12.6-0                        kubernetes 
kubectl.x86_64                       1.12.7-0                        kubernetes 
kubectl.x86_64                       1.12.8-0                        kubernetes 
kubectl.x86_64                       1.12.9-0                        kubernetes 
kubectl.x86_64                       1.12.10-0                       kubernetes 
kubectl.x86_64                       1.13.0-0                        kubernetes 
kubectl.x86_64                       1.13.1-0                        kubernetes 
kubectl.x86_64                       1.13.2-0                        kubernetes 
kubectl.x86_64                       1.13.3-0                        kubernetes 
kubectl.x86_64                       1.13.4-0                        kubernetes 
kubectl.x86_64                       1.13.5-0                        kubernetes 
kubectl.x86_64                       1.13.6-0                        kubernetes 
kubectl.x86_64                       1.13.7-0                        kubernetes 
kubectl.x86_64                       1.13.8-0                        kubernetes 
kubectl.x86_64                       1.13.9-0                        kubernetes 
kubectl.x86_64                       1.13.10-0                       kubernetes 
kubectl.x86_64                       1.13.11-0                       kubernetes 
kubectl.x86_64                       1.13.12-0                       kubernetes 
kubectl.x86_64                       1.14.0-0                        kubernetes 
kubectl.x86_64                       1.14.1-0                        kubernetes 
kubectl.x86_64                       1.14.2-0                        kubernetes 
kubectl.x86_64                       1.14.3-0                        kubernetes 
kubectl.x86_64                       1.14.4-0                        kubernetes 
kubectl.x86_64                       1.14.5-0                        kubernetes 
kubectl.x86_64                       1.14.6-0                        kubernetes 
kubectl.x86_64                       1.14.7-0                        kubernetes 
kubectl.x86_64                       1.14.8-0                        kubernetes 
kubectl.x86_64                       1.14.9-0                        kubernetes 
kubectl.x86_64                       1.14.10-0                       kubernetes 
kubectl.x86_64                       1.15.0-0                        kubernetes 
kubectl.x86_64                       1.15.1-0                        kubernetes 
kubectl.x86_64                       1.15.2-0                        kubernetes 
kubectl.x86_64                       1.15.3-0                        kubernetes 
kubectl.x86_64                       1.15.4-0                        kubernetes 
kubectl.x86_64                       1.15.5-0                        kubernetes 
kubectl.x86_64                       1.15.6-0                        kubernetes 
kubectl.x86_64                       1.15.7-0                        kubernetes 
kubectl.x86_64                       1.15.8-0                        kubernetes 
kubectl.x86_64                       1.15.9-0                        kubernetes 
kubectl.x86_64                       1.15.10-0                       kubernetes 
kubectl.x86_64                       1.15.11-0                       kubernetes 
kubectl.x86_64                       1.16.0-0                        kubernetes 
kubectl.x86_64                       1.16.1-0                        kubernetes 
kubectl.x86_64                       1.16.2-0                        kubernetes 
kubectl.x86_64                       1.16.3-0                        kubernetes 
kubectl.x86_64                       1.16.4-0                        kubernetes 
kubectl.x86_64                       1.16.5-0                        kubernetes 
kubectl.x86_64                       1.16.6-0                        kubernetes 
kubectl.x86_64                       1.16.7-0                        kubernetes 
kubectl.x86_64                       1.16.8-0                        kubernetes 
kubectl.x86_64                       1.16.9-0                        kubernetes 
kubectl.x86_64                       1.17.0-0                        kubernetes 
kubectl.x86_64                       1.17.1-0                        kubernetes 
kubectl.x86_64                       1.17.2-0                        kubernetes 
kubectl.x86_64                       1.17.3-0                        kubernetes 
kubectl.x86_64                       1.17.4-0                        kubernetes 
kubectl.x86_64                       1.17.5-0                        kubernetes 
kubectl.x86_64                       1.18.0-0                        kubernetes 
kubectl.x86_64                       1.18.1-0                        kubernetes 
kubectl.x86_64                       1.18.2-0                        kubernetes 
[root@k8s01 ~]# 
4月 222020
 

获取pod列表并查看pod运行的节点

[root@k8s01 ~]# kubectl get pods -o wide
NAME                               READY   STATUS    RESTARTS   AGE   IP            NODE    NOMINATED NODE   READINESS GATES
nginx-deployment-cc5db57d4-5q9lz   1/1     Running   0          22h   10.244.2.17   k8s03   <none>           <none>
nginx-deployment-cc5db57d4-dncbs   1/1     Running   0          22h   10.244.1.10   k8s02   <none>           <none>
nginx-deployment-cc5db57d4-gsp6l   1/1     Running   0          22h   10.244.2.16   k8s03   <none>           <none>
[root@k8s01 ~]#

修改副本数量为5并再次应用deployment配置(扩容)

[root@k8s01 ~]# vi nginx-deployment.yaml
  replicas: 5

[root@k8s01 ~]# kubectl apply -f nginx-deployment.yaml 
deployment.apps/nginx-deployment configured
[root@k8s01 ~]# kubectl get pods -o wide
NAME                               READY   STATUS    RESTARTS   AGE   IP            NODE    NOMINATED NODE   READINESS GATES
nginx-deployment-cc5db57d4-5q9lz   1/1     Running   0          23h   10.244.2.17   k8s03   <none>           <none>
nginx-deployment-cc5db57d4-clrlh   1/1     Running   0          9s    10.244.2.18   k8s03   <none>           <none>
nginx-deployment-cc5db57d4-dncbs   1/1     Running   0          23h   10.244.1.10   k8s02   <none>           <none>
nginx-deployment-cc5db57d4-gsp6l   1/1     Running   0          23h   10.244.2.16   k8s03   <none>           <none>
nginx-deployment-cc5db57d4-ndkr7   1/1     Running   0          9s    10.244.1.11   k8s02   <none>           <none>
[root@k8s01 ~]#

修改副本数量为2并再次应用deployment配置(缩容)

[root@k8s01 ~]# vi nginx-deployment.yaml
  replicas: 2

[root@k8s01 ~]# kubectl apply -f nginx-deployment.yaml 
deployment.apps/nginx-deployment configured
[root@k8s01 ~]# kubectl get pods -o wide
NAME                               READY   STATUS        RESTARTS   AGE     IP            NODE    NOMINATED NODE   READINESS GATES
nginx-deployment-cc5db57d4-clrlh   0/1     Terminating   0          4m50s   10.244.2.18   k8s03   <none>           <none>
nginx-deployment-cc5db57d4-dncbs   1/1     Running       0          23h     10.244.1.10   k8s02   <none>           <none>
nginx-deployment-cc5db57d4-gsp6l   0/1     Terminating   0          23h     10.244.2.16   k8s03   <none>           <none>
nginx-deployment-cc5db57d4-ndkr7   1/1     Running       0          4m50s   10.244.1.11   k8s02   <none>           <none>
[root@k8s01 ~]# 

[root@k8s01 ~]# kubectl get pods -o wide
NAME                               READY   STATUS    RESTARTS   AGE   IP            NODE    NOMINATED NODE   READINESS GATES
nginx-deployment-cc5db57d4-dncbs   1/1     Running   0          23h   10.244.1.10   k8s02   <none>           <none>
nginx-deployment-cc5db57d4-ndkr7   1/1     Running   0          22m   10.244.1.11   k8s02   <none>           <none>
[root@k8s01 ~]#
4月 222020
 

kubernetes 阿里云公共镜像仓库配置

适用于CentOS/RHEL/Fedora的配置

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
setenforce 0
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet

适用于Debian/Ubuntu的配置

apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF 
apt-get update
apt-get install -y kubelet kubeadm kubectl

Docker Hub 镜像缓存(USTC)适用于Ubuntu 16.04+/Debian 8+/CentOS 7版本

vi /etc/docker/daemon.json

{
  "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn/"]
}
    
sudo systemctl restart docker

Kubernetes容器集群之Deployment学习

 未分类  Kubernetes容器集群之Deployment学习已关闭评论
4月 222020
 

启用kubectl命令自动补全

[root@k8s01 ~]# yum -y install bash-completion
[root@k8s01 ~]# source /usr/share/bash-completion/bash_completion
[root@k8s01 ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc
[root@k8s01 ~]# exit
logout

准备Deployment配置文件

[root@k8s01 ~]# vi nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.17.10
        ports:
        - containerPort: 80

应用Deployment配置文件

[root@k8s01 ~]# kubectl apply -f nginx-deployment.yaml 
deployment.apps/nginx-deployment created
[root@k8s01 ~]#

获取deployments列表和pods列表

[root@k8s01 ~]# kubectl get deployments.apps 
NAME               READY   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3/3     3            3           22s
[root@k8s01 ~]# 
[root@k8s01 ~]# kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
nginx-deployment-cc5db57d4-5q9lz   1/1     Running   0          39s
nginx-deployment-cc5db57d4-dncbs   1/1     Running   0          39s
nginx-deployment-cc5db57d4-gsp6l   1/1     Running   0          39s
[root@k8s01 ~]#

查看deployment详情(deployment属于controller的一种类型,通过replicaset来管理pod,Events记录replicaset启动过程)

[root@k8s01 ~]# kubectl describe deployments.apps nginx-deployment 
Name:                   nginx-deployment
Namespace:              default
CreationTimestamp:      Tue, 21 Apr 2020 10:33:38 +0000
Labels:                 app=nginx
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=nginx
Replicas:               3 desired | 3 updated | 3 total | 3 available | 0 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=nginx
  Containers:
   nginx:
    Image:        nginx:1.17.10
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      True    MinimumReplicasAvailable
  Progressing    True    NewReplicaSetAvailable
OldReplicaSets:  <none>
NewReplicaSet:   nginx-deployment-cc5db57d4 (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  85s   deployment-controller  Scaled up replica set nginx-deployment-cc5db57d4 to 3
[root@k8s01 ~]#

获取replicaset列表(显示已就绪3个副本,Events为3个副本pod创建记录)

[root@k8s01 ~]# kubectl get replicasets.apps 
NAME                         DESIRED   CURRENT   READY   AGE
nginx-deployment-cc5db57d4   3         3         3       11m
[root@k8s01 ~]#

查看relicasets详情

[root@k8s01 ~]# kubectl describe replicasets.apps nginx-deployment-cc5db57d4 
Name:           nginx-deployment-cc5db57d4
Namespace:      default
Selector:       app=nginx,pod-template-hash=cc5db57d4
Labels:         app=nginx
                pod-template-hash=cc5db57d4
Annotations:    deployment.kubernetes.io/desired-replicas: 3
                deployment.kubernetes.io/max-replicas: 4
                deployment.kubernetes.io/revision: 1
Controlled By:  Deployment/nginx-deployment
Replicas:       3 current / 3 desired
Pods Status:    3 Running / 0 Waiting / 0 Succeeded / 0 Failed
Pod Template:
  Labels:  app=nginx
           pod-template-hash=cc5db57d4
  Containers:
   nginx:
    Image:        nginx:1.17.10
    Port:         80/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Events:
  Type    Reason            Age   From                   Message
  ----    ------            ----  ----                   -------
  Normal  SuccessfulCreate  13m   replicaset-controller  Created pod: nginx-deployment-cc5db57d4-gsp6l
  Normal  SuccessfulCreate  13m   replicaset-controller  Created pod: nginx-deployment-cc5db57d4-5q9lz
  Normal  SuccessfulCreate  13m   replicaset-controller  Created pod: nginx-deployment-cc5db57d4-dncbs
[root@k8s01 ~]#

获取pods列表(三个副本Pod都处于运行状态)

[root@k8s01 ~]# kubectl get pods
NAME                               READY   STATUS    RESTARTS   AGE
nginx-deployment-cc5db57d4-5q9lz   1/1     Running   0          15m
nginx-deployment-cc5db57d4-dncbs   1/1     Running   0          15m
nginx-deployment-cc5db57d4-gsp6l   1/1     Running   0          15m
[root@k8s01 ~]#

查看pods详情(Controolled By指明该pod由ReplicaSet控制生成,Events记录了该pod启动过程)

[root@k8s01 ~]# kubectl describe pods nginx-deployment-cc5db57d4-5q9lz
Name:         nginx-deployment-cc5db57d4-5q9lz
Namespace:    default
Priority:     0
Node:         k8s03/172.31.6.113
Start Time:   Tue, 21 Apr 2020 10:33:38 +0000
Labels:       app=nginx
              pod-template-hash=cc5db57d4
Annotations:  <none>
Status:       Running
IP:           10.244.2.17
IPs:
  IP:           10.244.2.17
Controlled By:  ReplicaSet/nginx-deployment-cc5db57d4
Containers:
  nginx:
    Container ID:   docker://e062b14bbf7670d5d3c45e983c88b36caa2ed3700fd03dbdb9adf06724fba9bf
    Image:          nginx:1.17.10
    Image ID:       docker-pullable://nginx@sha256:d81f010955749350ef31a119fb94b180fde8b2f157da351ff5667ae037968b28
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 21 Apr 2020 10:33:39 +0000
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-pkjh8 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             True 
  ContainersReady   True 
  PodScheduled      True 
Volumes:
  default-token-pkjh8:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-pkjh8
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age   From               Message
  ----    ------     ----  ----               -------
  Normal  Scheduled  16m   default-scheduler  Successfully assigned default/nginx-deployment-cc5db57d4-5q9lz to k8s03
  Normal  Pulled     16m   kubelet, k8s03     Container image "nginx:1.17.10" already present on machine
  Normal  Created    16m   kubelet, k8s03     Created container nginx
  Normal  Started    16m   kubelet, k8s03     Started container nginx
[root@k8s01 ~]#

流程总结:

(1)用户通过kubectl创建Deployment。
(2)Deployment创建ReplicaSet。
(3)ReplicaSet创建Pod。