附023.Kubernetes_v1.18.3高可用部署架構二

kubeadm介紹

kubeadm概述

參考《附003.Kubeadm部署Kubernetes》。

kubeadm功能

參考《附003.Kubeadm部署Kubernetes》。

本方案描述

  • 本方案採用kubeadm部署Kubernetes 1.18.3版本;
  • etcd採用混部方式;
  • KeepAlived:實現VIP高可用;
  • HAProxy:以系統systemd形式運行,提供反向代理至3個master 6443端口;
  • 其他主要部署組件包括:
    • Metrics:度量;
    • Dashboard:Kubernetes 圖形UI界面;
    • Helm:Kubernetes Helm包管理工具;
    • Ingress:Kubernetes 服務暴露;
    • Longhorn:Kubernetes 動態存儲組件。

部署規劃

節點規劃

節點主機名 IP 類型 運行服務
master01 172.24.8.71 Kubernetes master節點 docker、etcd、kube-apiserver、kube-scheduler、kube-controller-manager、
kubectl、kubelet、metrics、calico、HAProxy、KeepAlived
master02 172.24.8.72 Kubernetes master節點 docker、etcd、kube-apiserver、kube-scheduler、kube-controller-manager、
kubectl、kubelet、metrics、calico、HAProxy、KeepAlived
master03 172.24.8.73 Kubernetes master節點 docker、etcd、kube-apiserver、kube-scheduler、kube-controller-manager、
kubectl、kubelet、metrics、calico、HAProxy、KeepAlived
worker01 172.24.8.74 Kubernetes node節點1 docker、kubelet、proxy、calico
worker02 172.24.8.75 Kubernetes node節點2 docker、kubelet、proxy、calico
worker03 172.24.8.76 Kubernetes node節點3 docker、kubelet、proxy、calico
VIP 172.24.8.100

Kubernetes的高可用主要指的是控制平面的高可用,即指多套Master節點組件和Etcd組件,工作節點通過負載均衡連接到各Master。

Kubernetes高可用架構中etcd與Master節點組件混布方式特點:

  1. 所需機器資源少
  2. 部署簡單,利於管理
  3. 容易進行橫向擴展
  4. 風險大,一台宿主機掛了,master和etcd就都少了一套,集群冗餘度受到的影響比較大。

提示:本實驗使用Keepalived+HAProxy架構實現Kubernetes的高可用。

初始準備

[root@master01 ~]# hostnamectl set-hostname master01			#其他節點依次修改
[root@master01 ~]# cat >> /etc/hosts << EOF
172.24.8.71 master01
172.24.8.72 master02
172.24.8.73 master03
172.24.8.74 worker01
172.24.8.75 worker02
172.24.8.76 worker03
EOF

[root@master01 ~]# vi k8sinit.sh

# Initialize the machine. This needs to be executed on every machine.

# Install docker
useradd -m docker
yum -y install yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
mkdir /etc/docker
cat > /etc/docker/daemon.json <<EOF
{
  "registry-mirrors": ["https://dbzucv6w.mirror.aliyuncs.com"],
  "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 restart docker
systemctl enable docker
systemctl status docker

# Disable the SELinux.
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config

# Turn off and disable the firewalld.
systemctl stop firewalld
systemctl disable firewalld

# Modify related kernel parameters & Disable the swap.
cat > /etc/sysctl.d/k8s.conf << EOF
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.tcp_tw_recycle = 0
vm.swappiness = 0
vm.overcommit_memory = 1
vm.panic_on_oom = 0
net.ipv6.conf.all.disable_ipv6 = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf >&/dev/null
swapoff -a
sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
modprobe br_netfilter

# Add ipvs modules
cat > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
modprobe -- nf_conntrack
EOF

chmod 755 /etc/sysconfig/modules/ipvs.modules
bash /etc/sysconfig/modules/ipvs.modules

# Install rpm
yum install -y conntrack ntpdate ntp ipvsadm ipset jq iptables curl sysstat libseccomp wget

# Update kernel
rpm --import http://down.linuxsb.com:8888/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://down.linuxsb.com:8888/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
yum --disablerepo="*" --enablerepo="elrepo-kernel" install -y kernel-ml
sed -i 's/^GRUB_DEFAULT=.*/GRUB_DEFAULT=0/' /etc/default/grub
grub2-mkconfig -o /boot/grub2/grub.cfg
yum update -y

# Reboot the machine.
# reboot

提示:對於某些特性,可能需要升級內核,內核升級操作見《018.Linux升級內核》。
4.19版及以上內核nf_conntrack_ipv4已經改為nf_conntrack。

互信配置

為了更方便遠程分發文件和執行命令,本實驗配置master01節點到其它節點的 ssh 信任關係。

[root@master01 ~]# ssh-keygen -f ~/.ssh/id_rsa -N ''
[root@master01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@master01
[root@master01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@master02
[root@master01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@master03
[root@master01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@worker01
[root@master01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@worker02
[root@master01 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@worker03

提示:此操作僅需要在master節點操作。

其他準備

[root@master01 ~]# vi environment.sh

#!/bin/sh
#****************************************************************#
# ScriptName: environment.sh
# Author: xhy
# Create Date: 2020-05-30 16:30
# Modify Author: xhy
# Modify Date: 2020-06-15 17:55
# Version: 
#***************************************************************#
# 集群 MASTER 機器 IP 數組
export MASTER_IPS=(172.24.8.71 172.24.8.72 172.24.8.73)

# 集群 MASTER IP 對應的主機名數組
export MASTER_NAMES=(master01 master02 master03)

# 集群 NODE 機器 IP 數組
export NODE_IPS=(172.24.8.74 172.24.8.75 172.24.8.76)

# 集群 NODE IP 對應的主機名數組
export NODE_NAMES=(worker01 worker02 worker03)

# 集群所有機器 IP 數組
export ALL_IPS=(172.24.8.71 172.24.8.72 172.24.8.73 172.24.8.74 172.24.8.75 172.24.8.76)

# 集群所有IP 對應的主機名數組
export ALL_NAMES=(master01 master02 master03 worker01 worker02 worker03)
[root@master01 ~]# source environment.sh
[root@master01 ~]# chmod +x *.sh
[root@master01 ~]# for all_ip in ${ALL_IPS[@]}
  do
    echo ">>> ${all_ip}"
    scp -rp /etc/hosts root@${all_ip}:/etc/hosts
    scp -rp k8sinit.sh root@${all_ip}:/root/
    ssh root@${all_ip} "bash /root/k8sinit.sh"
  done

集群部署

相關組件包

需要在每台機器上都安裝以下的軟件包:

  • kubeadm: 用來初始化集群的指令;
  • kubelet: 在集群中的每個節點上用來啟動 pod 和 container 等;
  • kubectl: 用來與集群通信的命令行工具。

kubeadm不能安裝或管理 kubelet 或 kubectl ,所以得保證他們滿足通過 kubeadm 安裝的 Kubernetes 控制層對版本的要求。如果版本沒有滿足要求,可能導致一些意外錯誤或問題。
具體相關組件安裝見《附001.kubectl介紹及使用》

提示:Kubernetes 1.18版本所有兼容相應組件的版本參考:https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.18.md。

正式安裝

[root@master01 ~]# for all_ip in ${ALL_IPS[@]}
  do
    echo ">>> ${all_ip}"
    ssh root@${all_ip} "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"
    ssh root@${all_ip} "yum install -y kubeadm-1.18.3-0.x86_64 kubelet-1.18.3-0.x86_64 kubectl-1.18.3-0.x86_64 --disableexcludes=kubernetes"
    ssh root@${all_ip} "systemctl enable kubelet"
done
[root@master01 ~]# yum search -y kubelet --showduplicates		#查看相應版本

提示:如上僅需Master01節點操作,從而實現所有節點自動化安裝,同時此時不需要啟動kubelet,初始化的過程中會自動啟動的,如果此時啟動了會出現報錯,忽略即可。
說明:同時安裝了cri-tools, kubernetes-cni, socat三個依賴:
socat:kubelet的依賴;
cri-tools:即CRI(Container Runtime Interface)容器運行時接口的命令行工具。

部署高可用組件

HAProxy安裝

[root@master01 ~]# for master_ip in ${MASTER_IPS[@]}
  do
    echo ">>> ${master_ip}"
    ssh root@${master_ip} "yum -y install gcc gcc-c++ make libnl libnl-devel libnfnetlink-devel openssl-devel wget openssh-clients systemd-devel zlib-devel pcre-devel libnl3-devel"
    ssh root@${master_ip} "wget http://down.linuxsb.com:8888/software/haproxy-2.1.6.tar.gz"
    ssh root@${master_ip} "tar -zxvf haproxy-2.1.6.tar.gz"
    ssh root@${master_ip} "cd haproxy-2.1.6/ && make ARCH=x86_64 TARGET=linux-glibc USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 PREFIX=/usr/local/haprpxy && make install PREFIX=/usr/local/haproxy"
    ssh root@${master_ip} "cp /usr/local/haproxy/sbin/haproxy /usr/sbin/"
    ssh root@${master_ip} "useradd -r haproxy && usermod -G haproxy haproxy"
    ssh root@${master_ip} "mkdir -p /etc/haproxy && cp -r /root/haproxy-2.1.6/examples/errorfiles/ /usr/local/haproxy/"
  done

Keepalived安裝

[root@master01 ~]# for master_ip in ${MASTER_IPS[@]}
  do
    echo ">>> ${master_ip}"
    ssh root@${master_ip} "yum -y install gcc gcc-c++ make libnl libnl-devel libnfnetlink-devel openssl-devel"
    ssh root@${master_ip} "wget http://down.linuxsb.com:8888/software/keepalived-2.0.20.tar.gz"
    ssh root@${master_ip} "tar -zxvf keepalived-2.0.20.tar.gz"
    ssh root@${master_ip} "cd keepalived-2.0.20/ && ./configure --sysconf=/etc --prefix=/usr/local/keepalived && make && make install"
  done

提示:如上僅需Master01節點操作,從而實現所有節點自動化安裝。

創建配置文件

[root@master01 ~]# wget http://down.linuxsb.com:8888/hakek8s.sh		#拉取自動部署腳本
[root@master01 ~]# chmod u+x hakek8s.sh

[root@master01 ~]# vi hakek8s.sh

#!/bin/sh
#****************************************************************#
# ScriptName: hakek8s.sh
# Author: xhy
# Create Date: 2020-06-08 20:00
# Modify Author: xhy
# Modify Date: 2020-06-15 18:15
# Version: v2
#***************************************************************#

#######################################
# set variables below to create the config files, all files will create at ./config directory
#######################################

# master keepalived virtual ip address
export K8SHA_VIP=172.24.8.100

# master01 ip address
export K8SHA_IP1=172.24.8.71

# master02 ip address
export K8SHA_IP2=172.24.8.72

# master03 ip address
export K8SHA_IP3=172.24.8.73

# master01 hostname
export K8SHA_HOST1=master01

# master02 hostname
export K8SHA_HOST2=master02

# master03 hostname
export K8SHA_HOST3=master03

# master01 network interface name
export K8SHA_NETINF1=eth0

# master02 network interface name
export K8SHA_NETINF2=eth0

# master03 network interface name
export K8SHA_NETINF3=eth0

# keepalived auth_pass config
export K8SHA_KEEPALIVED_AUTH=412f7dc3bfed32194d1600c483e10ad1d

# kubernetes CIDR pod subnet
export K8SHA_PODCIDR=10.10.0.0

# kubernetes CIDR svc subnet
export K8SHA_SVCCIDR=10.20.0.0

[root@master01 ~]# ./hakek8s.sh

解釋:如上僅需Master01節點操作。執行hakek8s.sh腳本後會生產如下配置文件清單:

  • kubeadm-config.yaml:kubeadm初始化配置文件,位於當前目錄
  • keepalived:keepalived配置文件,位於各個master節點的/etc/keepalived目錄
  • haproxy:haproxy的配置文件,位於各個master節點的/etc/haproxy/目錄
  • calico.yaml:calico網絡組件部署文件,位於config/calico/目錄

[root@master01 ~]# cat kubeadm-config.yaml #檢查集群初始化配置

apiVersion: kubeadm.k8s.io/v1beta2
kind: ClusterConfiguration
networking:
  serviceSubnet: "10.20.0.0/16"				#設置svc網段
  podSubnet: "10.10.0.0/16"				#設置Pod網段
  dnsDomain: "cluster.local"
kubernetesVersion: "v1.18.3"				#設置安裝版本
controlPlaneEndpoint: "172.24.11.254:16443"		#設置相關API VIP地址
apiServer:
  certSANs:
  - master01
  - master02
  - master03
  - 127.0.0.1
  - 192.168.2.11
  - 192.168.2.12
  - 192.168.2.13
  - 192.168.2.200
  timeoutForControlPlane: 4m0s
certificatesDir: "/etc/kubernetes/pki"
imageRepository: "k8s.gcr.io"

---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
featureGates:
  SupportIPVSProxyMode: true
mode: ipvs

提示:如上僅需Master01節點操作,更多config文件參考:https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2。
此kubeadm部署初始化配置更多參考:https://pkg.go.dev/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2?tab=doc。

啟動服務

[root@master01 ~]# cat /etc/keepalived/keepalived.conf
[root@master01 ~]# cat /etc/keepalived/check_apiserver.sh	確認Keepalived配置
[root@master01 ~]# for master_ip in ${MASTER_IPS[@]}
  do
    echo ">>> ${master_ip}"
    ssh root@${master_ip} "systemctl start haproxy.service && systemctl enable haproxy.service"
    ssh root@${master_ip} "systemctl start keepalived.service && systemctl enable keepalived.service"
    ssh root@${master_ip} "systemctl status keepalived.service | grep Active"
    ssh root@${master_ip} "systemctl status haproxy.service | grep Active"
  done
[root@master01 ~]# for all_ip in ${ALL_IPS[@]}
  do
    echo ">>> ${all_ip}"
    ssh root@${all_ip} "ping -c1 172.24.8.100"
  done								#等待30s執行檢查

提示:如上僅需Master01節點操作,從而實現所有節點自動啟動服務。

初始化集群

拉取鏡像

[root@master01 ~]# kubeadm --kubernetes-version=v1.18.3 config images list	#列出所需鏡像
[root@master01 ~]# cat config/downimage.sh			#確認版本
#!/bin/sh
#****************************************************************#
# ScriptName: downimage.sh
# Author: xhy
# Create Date: 2020-05-29 19:55
# Modify Author: xhy
# Modify Date: 2020-06-10 19:15
# Version: v2
#***************************************************************#

KUBE_VERSION=v1.18.3
CALICO_VERSION=v3.14.1
CALICO_URL=calico
KUBE_PAUSE_VERSION=3.2
ETCD_VERSION=3.4.3-0
CORE_DNS_VERSION=1.6.7
GCR_URL=k8s.gcr.io
METRICS_SERVER_VERSION=v0.3.6
INGRESS_VERSION=0.32.0
CSI_PROVISIONER_VERSION=v1.4.0
CSI_NODE_DRIVER_VERSION=v1.2.0
CSI_ATTACHER_VERSION=v2.0.0
CSI_RESIZER_VERSION=v0.3.0 
ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers
UCLOUD_URL=uhub.service.ucloud.cn/uxhy
QUAY_URL=quay.io

kubeimages=(kube-proxy:${KUBE_VERSION}
kube-scheduler:${KUBE_VERSION}
kube-controller-manager:${KUBE_VERSION}
kube-apiserver:${KUBE_VERSION}
pause:${KUBE_PAUSE_VERSION}
etcd:${ETCD_VERSION}
coredns:${CORE_DNS_VERSION}
metrics-server-amd64:${METRICS_SERVER_VERSION}
)

for kubeimageName in ${kubeimages[@]} ; do
docker pull $UCLOUD_URL/$kubeimageName
docker tag $UCLOUD_URL/$kubeimageName $GCR_URL/$kubeimageName
docker rmi $UCLOUD_URL/$kubeimageName
done

calimages=(cni:${CALICO_VERSION}
pod2daemon-flexvol:${CALICO_VERSION}
node:${CALICO_VERSION}
kube-controllers:${CALICO_VERSION})

for calimageName in ${calimages[@]} ; do
docker pull $UCLOUD_URL/$calimageName
docker tag $UCLOUD_URL/$calimageName $CALICO_URL/$calimageName
docker rmi $UCLOUD_URL/$calimageName
done

ingressimages=(nginx-ingress-controller:${INGRESS_VERSION})

for ingressimageName in ${ingressimages[@]} ; do
docker pull $UCLOUD_URL/$ingressimageName
docker tag $UCLOUD_URL/$ingressimageName $QUAY_URL/kubernetes-ingress-controller/$ingressimageName
docker rmi $UCLOUD_URL/$ingressimageName
done

csiimages=(csi-provisioner:${CSI_PROVISIONER_VERSION}
csi-node-driver-registrar:${CSI_NODE_DRIVER_VERSION}
csi-attacher:${CSI_ATTACHER_VERSION}
csi-resizer:${CSI_RESIZER_VERSION}
)

for csiimageName in ${csiimages[@]} ; do
docker pull $UCLOUD_URL/$csiimageName
docker tag $UCLOUD_URL/$csiimageName $QUAY_URL/k8scsi/$csiimageName
docker rmi $UCLOUD_URL/$csiimageName
done
[root@master01 ~]# for all_ip in ${ALL_IPS[@]}
  do
    echo ">>> ${all_ip}"
    scp -rp config/downimage.sh root@${all_ip}:/root/
    ssh root@${all_ip} "bash downimage.sh &"
  done

提示:如上僅需Master01節點操作,從而實現所有節點自動拉取鏡像。

[root@master01 ~]# docker images #確認驗證 

Master上初始化

[root@master01 ~]# kubeadm init --config=kubeadm-config.yaml --upload-certs 

You can now join any number of the control-plane node running the following command on each as root:

  kubeadm join 172.24.8.100:16443 --token xifg5c.3mvph3nwx1srdf7l \
    --discovery-token-ca-cert-hash sha256:031a8758ddad5431be4132ecd6445f33b17c2192c11e010209705816a4a53afd \
    --control-plane --certificate-key 560c926e508ed6011cd35fe120a5163d3ca32e16b745cf1877da970e3e0982f0

Please note that the certificate-key gives access to cluster sensitive data, keep it secret!
As a safeguard, uploaded-certs will be deleted in two hours; If necessary, you can use
"kubeadm init phase upload-certs --upload-certs" to reload certs afterward.

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 172.24.8.100:16443 --token xifg5c.3mvph3nwx1srdf7l \
    --discovery-token-ca-cert-hash sha256:031a8758ddad5431be4132ecd6445f33b17c2192c11e010209705816a4a53afd

注意:如上token具有默認24小時的有效期,token和hash值可通過如下方式獲取:
kubeadm token list
如果 Token 過期以後,可以輸入以下命令,生成新的 Token:

kubeadm token create
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
[root@master01 ~]# mkdir -p $HOME/.kube
[root@master01 ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master01 ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
[root@master01 ~]# cat << EOF >> ~/.bashrc
export KUBECONFIG=$HOME/.kube/config
EOF							#設置KUBECONFIG環境變量
[root@master01 ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc
[root@master01 ~]# source ~/.bashrc

附加:初始化過程大致步驟如下:

  • [kubelet-start] 生成kubelet的配置文件”/var/lib/kubelet/config.yaml”
  • [certificates]生成相關的各種證書
  • [kubeconfig]生成相關的kubeconfig文件
  • [bootstraptoken]生成token記錄下來,後邊使用kubeadm join往集群中添加節點時會用到

提示:初始化僅需要在master01上執行,若初始化異常可通過kubeadm reset && rm -rf $HOME/.kube重置。

添加其他master節點

[root@master02 ~]# kubeadm join 172.24.8.100:16443 --token xifg5c.3mvph3nwx1srdf7l \
    --discovery-token-ca-cert-hash sha256:031a8758ddad5431be4132ecd6445f33b17c2192c11e010209705816a4a53afd \
    --control-plane --certificate-key 560c926e508ed6011cd35fe120a5163d3ca32e16b745cf1877da970e3e0982f0

[root@master02 ~]# mkdir -p $HOME/.kube
[root@master02 ~]# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
[root@master02 ~]# sudo chown $(id -u):$(id -g) $HOME/.kube/config
[root@master02 ~]# cat << EOF >> ~/.bashrc
export KUBECONFIG=$HOME/.kube/config
EOF							#設置KUBECONFIG環境變量
[root@master02 ~]# echo "source <(kubectl completion bash)" >> ~/.bashrc
[root@master02 ~]# source ~/.bashrc

提示:master03也如上執行添加至集群的controlplane。
提示:若添加異常可通過kubeadm reset && rm -rf $HOME/.kube重置。

安裝NIC插件

NIC插件介紹

  • Calico 是一個安全的 L3 網絡和網絡策略提供者。
  • Canal 結合 Flannel 和 Calico, 提供網絡和網絡策略。
  • Cilium 是一個 L3 網絡和網絡策略插件, 能夠透明的實施 HTTP/API/L7 策略。 同時支持路由(routing)和疊加/封裝( overlay/encapsulation)模式。
  • Contiv 為多種用例提供可配置網絡(使用 BGP 的原生 L3,使用 vxlan 的 overlay,經典 L2 和 Cisco-SDN/ACI)和豐富的策略框架。Contiv 項目完全開源。安裝工具同時提供基於和不基於 kubeadm 的安裝選項。
  • Flannel 是一個可以用於 Kubernetes 的 overlay 網絡提供者。
  • Romana 是一個 pod 網絡的層 3 解決方案,並且支持 NetworkPolicy API。Kubeadm add-on 安裝細節可以在這裏找到。
  • Weave Net 提供了在網絡分組兩端參与工作的網絡和網絡策略,並且不需要額外的數據庫。
  • CNI-Genie 使 Kubernetes 無縫連接到一種 CNI 插件,例如:Flannel、Calico、Canal、Romana 或者 Weave。
    提示:本方案使用Calico插件。

設置標籤

[root@master01 ~]# kubectl taint nodes --all node-role.kubernetes.io/master- #允許master部署應用

提示:部署完內部應用后可使用kubectl taint node master01 node-role.kubernetes.io/master=””:NoSchedule重新設置Master為Master Only 狀態。

部署calico

[root@master01 ~]# cat config/calico/calico.yaml			#檢查配置
……
            - name: CALICO_IPV4POOL_CIDR
              value: "10.10.0.0/16"					#檢查Pod網段
……
            - name: IP_AUTODETECTION_METHOD
              value: "interface=eth.*"					#檢查節點之間的網卡
# Auto-detect the BGP IP address.
            - name: IP
              value: "autodetect"
……
[root@master01 ~]# kubectl apply -f config/calico/calico.yaml
[root@master01 ~]# kubectl get pods --all-namespaces -o wide		#查看部署
[root@master01 ~]# kubectl get nodes

修改node端口範圍

[root@master01 ~]# vi /etc/kubernetes/manifests/kube-apiserver.yaml
……
    - --service-node-port-range=1-65535
……

提示:如上僅需在所有Master節點操作。

添加Worker節點

添加Worker節點

[root@master01 ~]# for node_ip in ${NODE_IPS[@]}
  do
    echo ">>> ${node_ip}"
    ssh root@${node_ip} "kubeadm join 172.24.8.100:16443 --token xifg5c.3mvph3nwx1srdf7l \
    --discovery-token-ca-cert-hash sha256:031a8758ddad5431be4132ecd6445f33b17c2192c11e010209705816a4a53afd"
    ssh root@${node_ip} "systemctl enable kubelet.service"
  done

提示:如上僅需Master01節點操作,從而實現所有Worker節點添加至集群,若添加異常可通過如下方式重置:

[root@node01 ~]# kubeadm reset
[root@node01 ~]# ifconfig cni0 down
[root@node01 ~]# ip link delete cni0
[root@node01 ~]# ifconfig flannel.1 down
[root@node01 ~]# ip link delete flannel.1
[root@node01 ~]# rm -rf /var/lib/cni/

確認驗證

[root@master01 ~]# kubectl get nodes					#節點狀態
[root@master01 ~]# kubectl get cs					#組件狀態
[root@master01 ~]# kubectl get serviceaccount				#服務賬戶
[root@master01 ~]# kubectl cluster-info					#集群信息
[root@master01 ~]# kubectl get pod -n kube-system -o wide		#所有服務狀態

提示:更多Kubetcl使用參考:https://kubernetes.io/docs/reference/kubectl/kubectl/
https://kubernetes.io/docs/reference/kubectl/overview/
更多kubeadm使用參考:https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm/

Metrics部署

Metrics介紹

Kubernetes的早期版本依靠Heapster來實現完整的性能數據採集和監控功能,Kubernetes從1.8版本開始,性能數據開始以Metrics API的方式提供標準化接口,並且從1.10版本開始將Heapster替換為Metrics Server。在Kubernetes新的監控體系中,Metrics Server用於提供核心指標(Core Metrics),包括Node、Pod的CPU和內存使用指標。
對其他自定義指標(Custom Metrics)的監控則由Prometheus等組件來完成。

開啟聚合層

有關聚合層知識參考:https://blog.csdn.net/liukuan73/article/details/81352637
kubeadm方式部署默認已開啟。

獲取部署文件

[root@master01 ~]# mkdir metrics
[root@master01 ~]# cd metrics/
[root@master01 metrics]# wget https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml
[root@master01 metrics]# vi components.yaml
……
apiVersion: apps/v1
kind: Deployment
……
spec:
  replicas: 3						#根據集群規模調整副本數
……
    spec:
      hostNetwork: true
……
      - name: metrics-server
        image: k8s.gcr.io/metrics-server-amd64:v0.3.6
        imagePullPolicy: IfNotPresent
        args:
          - --cert-dir=/tmp
          - --secure-port=4443
          - --kubelet-insecure-tls
          - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP	#追加此args
……

正式部署

[root@master01 metrics]# kubectl apply -f components.yaml
[root@master01 metrics]# kubectl -n kube-system get pods -l k8s-app=metrics-server
NAME                              READY   STATUS    RESTARTS   AGE
metrics-server-7b97647899-8txt4   1/1     Running   0          53s
metrics-server-7b97647899-btdwp   1/1     Running   0          53s
metrics-server-7b97647899-kbr8b   1/1     Running   0          53s

查看資源監控

[root@k8smaster01 ~]# kubectl top nodes 
[root@master01 metrics]# kubectl top pods --all-namespaces

提示:Metrics Server提供的數據也可以供HPA控制器使用,以實現基於CPU使用率或內存使用值的Pod自動擴縮容功能。
部署參考:https://linux48.com/container/2019-11-13-metrics-server.html
有關metrics更多部署參考:
https://kubernetes.io/docs/tasks/debug-application-cluster/resource-metrics-pipeline/
開啟開啟API Aggregation參考:
https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/apiserver-aggregation/
API Aggregation介紹參考:
https://kubernetes.io/docs/tasks/access-kubernetes-api/configure-aggregation-layer/

Nginx ingress部署

參考《附020.Nginx-ingress部署及使用》

Dashboard部署

設置標籤

[root@master01 ~]# kubectl label nodes master01 dashboard=yes
[root@master01 ~]# kubectl label nodes master02 dashboard=yes
[root@master01 ~]# kubectl label nodes master03 dashboard=yes

創建證書

本實驗已獲取免費一年的證書,免費證書獲取可參考:https://freessl.cn。

[root@master01 ~]# mkdir -p /root/dashboard/certs
[root@master01 ~]# cd /root/dashboard/certs
[root@master01 certs]# mv k8s.odocker.com tls.crt
[root@master01 certs]# mv k8s.odocker.com tls.crt
[root@master01 certs]# ll
total 8.0K
-rw-r--r-- 1 root root 1.9K Jun  8 11:46 tls.crt
-rw-r--r-- 1 root root 1.7K Jun  8 11:46 tls.ke

提示:也可手動如下操作創建自簽證書:

[root@master01 ~]# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout tls.key -out tls.crt -subj "/C=CN/ST=ZheJiang/L=HangZhou/O=Xianghy/OU=Xianghy/CN=k8s.odocker.com"

手動創建secret

[root@master01 ~]# kubectl create ns kubernetes-dashboard							#v2版本dashboard獨立ns
[root@master01 ~]# kubectl create secret generic kubernetes-dashboard-certs --from-file=$HOME/dashboard/certs/ -n kubernetes-dashboard
[root@master01 ~]# kubectl get secret kubernetes-dashboard-certs -n kubernetes-dashboard -o yaml		#查看新證書
NAME                         TYPE     DATA   AGE
kubernetes-dashboard-certs   Opaque   2      4s

下載yaml

[root@master01 ~]# cd /root/dashboard
[root@master01 dashboard]# wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.1/aio/deploy/recommended.yaml

修改為yaml

[root@master01 dashboard]# vi recommended.yaml

……
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  type: NodePort				#新增
  ports:
    - port: 443
      targetPort: 8443
      nodePort: 30001				#新增
  selector:
    k8s-app: kubernetes-dashboard
---
……						#如下全部註釋
#apiVersion: v1
#kind: Secret
#metadata:
#  labels:
#    k8s-app: kubernetes-dashboard
#  name: kubernetes-dashboard-certs
#  namespace: kubernetes-dashboard
#type: Opaque
……
kind: Deployment
……
  replicas: 3					#適當調整為3副本
……
          imagePullPolicy: IfNotPresent		#修改鏡像下載策略
          ports:
            - containerPort: 8443
              protocol: TCP
          args:
            - --auto-generate-certificates
            - --namespace=kubernetes-dashboard
            - --tls-key-file=tls.key
            - --tls-cert-file=tls.crt
            - --token-ttl=3600    #追加如上args
……
      nodeSelector:
        "beta.kubernetes.io/os": linux
        "dashboard": "yes"			#部署在master節點
……
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: dashboard-metrics-scraper
  name: dashboard-metrics-scraper
  namespace: kubernetes-dashboard
spec:
  type: NodePort				#新增
  ports:
    - port: 8000
      nodePort: 30000				#新增
      targetPort: 8000
  selector:                                                                                  
    k8s-app: dashboard-metrics-scraper
……
   replicas: 3					#適當調整為3副本
……
      nodeSelector:
        "beta.kubernetes.io/os": linux
        "dashboard": "yes"			#部署在master節點
……

正式部署

[root@master01 dashboard]# kubectl apply -f recommended.yaml
[root@master01 dashboard]# kubectl get deployment kubernetes-dashboard -n kubernetes-dashboard
[root@master01 dashboard]# kubectl get services -n kubernetes-dashboard
[root@master01 dashboard]# kubectl get pods -o wide -n kubernetes-dashboard


提示:master01 NodePort 30001/TCP映射到 dashboard pod 443 端口。

創建管理員賬戶

提示:dashboard v2版本默認沒有創建具有管理員權限的賬戶,可如下操作創建。

[root@master01 dashboard]# vi dashboard-admin.yaml 

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard

[root@master01 dashboard]# kubectl apply -f dashboard-admin.yaml

Ingress暴露Dashboard

創建Ingress tls

[root@master01 ~]# cd /root/dashboard/certs
[root@master01 certs]# kubectl -n kubernetes-dashboard create secret tls kubernetes-dashboard-tls --cert=tls.crt --key=tls.key
[root@master01 certs]# kubectl -n kubernetes-dashboard describe secrets kubernetes-dashboard-tls

創建ingress策略

[root@master01 ~]# cd /root/dashboard/
[root@master01 dashboard]# vi dashboard-ingress.yaml
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: kubernetes-dashboard-ingress
  namespace: kubernetes-dashboard
  annotations:
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/ssl-passthrough: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    #nginx.ingress.kubernetes.io/secure-backends: "true"
    nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    nginx.ingress.kubernetes.io/configuration-snippet: |
      proxy_ssl_session_reuse off;
spec:
  rules:
  - host: k8s.odocker.com
    http:
      paths:
      - path: /
        backend:
          serviceName: kubernetes-dashboard
          servicePort: 443
  tls:
  - hosts:
    - k8s.odocker.com
    secretName: kubernetes-dashboard-tls
[root@master01 dashboard]# kubectl apply -f dashboard-ingress.yaml
[root@master01 dashboard]# kubectl -n kubernetes-dashboard get ingress

訪問Dashboard

導入證書

將k8s.odocker.com導入瀏覽器,並設置為信任,導入操作略。

創建kubeconfig文件

使用token相對複雜,可將token添加至kubeconfig文件中,使用KubeConfig文件訪問dashboard。

[root@master01 dashboard]# ADMIN_SECRET=$(kubectl -n kubernetes-dashboard get secret | grep admin-user | awk '{print $1}')
[root@master01 dashboard]# DASHBOARD_LOGIN_TOKEN=$(kubectl describe secret -n kubernetes-dashboard ${ADMIN_SECRET} | grep -E '^token' | awk '{print $2}')
[root@master01 dashboard]# kubectl config set-cluster kubernetes \
  --certificate-authority=/etc/kubernetes/pki/ca.crt \
  --embed-certs=true \
  --server=172.24.8.100:16443 \
  --kubeconfig=local-hakek8s-dashboard-admin.kubeconfig								# 設置集群參數
[root@master01 dashboard]# kubectl config set-credentials dashboard_user \
  --token=${DASHBOARD_LOGIN_TOKEN} \
  --kubeconfig=local-hakek8s-dashboard-admin.kubeconfig								# 設置客戶端認證參數,使用上面創建的 Token
[root@master01 dashboard]# kubectl config set-context default \
  --cluster=kubernetes \
  --user=dashboard_user \
  --kubeconfig=local-hakek8s-dashboard-admin.kubeconfig								# 設置上下文參數
[root@master01 dashboard]# kubectl config use-context default --kubeconfig=local-hakek8s-dashboard-admin.kubeconfig		# 設置默認上下文

測試訪問Dashboard

本實驗採用ingress所暴露的域名:https://k8s.odocker.com 方式訪問。
使用local-hakek8s-dashboard-admin.kubeconfig文件訪問:

提示:更多dashboard訪問方式及認證可參考 《附004.Kubernetes Dashboard簡介及使用》。
dashboard登錄整個流程可參考:https://www.cnadn.net/post/2613.html

Longhorn存儲部署

Longhorn概述

Longhorn是用於Kubernetes的開源分佈式塊存儲系統。
提示:更多介紹參考:https://github.com/longhorn/longhorn。

Longhorn部署

[root@master01 ~]# source environment.sh
[root@master01 ~]# for all_ip in ${ALL_IPS[@]}
  do
    echo ">>> ${all_ip}"
    ssh root@${all_ip} "yum -y install iscsi-initiator-utils &"
  done

提示:所有節點都需要安裝。

[root@master01 ~]# mkdir longhorn
[root@master01 ~]# cd longhorn/
[root@master01 longhorn]# wget \
https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/longhorn.yaml
[root@master01 longhorn]# vi longhorn.yaml
#……
---
kind: Service
apiVersion: v1
metadata:
  labels:
    app: longhorn-ui
  name: longhorn-frontend
  namespace: longhorn-system
spec:
  type: NodePort			#修改為nodeport
  selector:
    app: longhorn-ui
  ports:
  - port: 80
    targetPort: 8000
    nodePort: 30002
---
……
kind: DaemonSet
……
        imagePullPolicy: IfNotPresent
……
#……
[root@master01 longhorn]# kubectl apply -f longhorn.yaml
[root@master01 longhorn]# kubectl -n longhorn-system get pods -o wide

提示:若部署異常可刪除重建,若出現無法刪除namespace,可通過如下操作進行刪除:
wget https://github.com/longhorn/longhorn/blob/master/uninstall/uninstall.yaml
rm -rf /var/lib/longhorn/
kubectl apply -f uninstall.yaml
kubectl delete -f longhorn.yaml

動態sc創建

提示:默認longhorn部署完成已創建一個sc,也可通過如下手動編寫yaml創建。

[root@master01 longhorn]# kubectl get sc
NAME                   PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
……
longhorn               driver.longhorn.io      Delete          Immediate              true                   15m
[root@master01 longhorn]# vi longhornsc.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: longhornsc
provisioner: rancher.io/longhorn
parameters:
  numberOfReplicas: "3"
  staleReplicaTimeout: "30"
  fromBackup: "" 

[root@master01 longhorn]# kubectl create -f longhornsc.yaml 

測試PV及PVC

[root@master01 longhorn]# vi longhornpod.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: longhorn-pvc
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 2Gi
---
apiVersion: v1
kind: Pod
metadata:
  name: longhorn-pod
  namespace: default
spec:
  containers:
  - name: volume-test
    image: nginx:stable-alpine
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: volv
      mountPath: /data
    ports:
    - containerPort: 80
  volumes:
  - name: volv
    persistentVolumeClaim:
      claimName: longhorn-pvc
[root@master01 longhorn]# kubectl apply -f longhornpod.yaml
[root@master01 longhorn]# kubectl get pods
[root@master01 longhorn]# kubectl get pvc
[root@master01 longhorn]# kubectl get pv

Ingress暴露Longhorn

[root@master01 longhorn]# yum -y install httpd-tools
[root@master01 longhorn]# htpasswd -c auth xhy				#創建用戶名和密碼

提示:也可通過如下命令創建:
USER=xhy; PASSWORD=x120952576; echo "${USER}:$(openssl passwd -stdin -apr1 <<< ${PASSWORD})" >> auth

[root@master01 longhorn]# kubectl -n longhorn-system create secret generic longhorn-basic-auth --from-file=auth 
[root@master01 longhorn]# vi longhorn-ingress.yaml #創建ingress規則

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: longhorn-ingress
  namespace: longhorn-system
  annotations:
    nginx.ingress.kubernetes.io/auth-type: basic
    nginx.ingress.kubernetes.io/auth-secret: longhorn-basic-auth
    nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required '
spec:
  rules:
  - host: longhorn.odocker.com
    http:
      paths:
      - path: /
        backend:
          serviceName: longhorn-frontend
          servicePort: 80

[root@master01 longhorn]# kubectl apply -f longhorn-ingress.yaml 

確認驗證

瀏覽器訪問:longhorn.odocker.com,並輸入賬號和密碼。

Helm安裝

參考《053.集群管理-Helm工具》

本站聲明:網站內容來源於博客園,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※超省錢租車方案

※別再煩惱如何寫文案,掌握八大原則!

※回頭車貨運收費標準

※教你寫出一流的銷售文案?

※產品缺大量曝光嗎?你需要的是一流包裝設計!

※廣告預算用在刀口上,台北網頁設計公司幫您達到更多曝光效益

升溫不超過2°C的變數 全球農業氮肥「一氧化二氮預算」首出爐

環境資訊中心外電;姜唯 翻譯;林大利 審校;稿源:Carbon Brief

Carbon Brief報導,根據全球碳計畫(Global Carbon Project)的研究,全世界用於生產糧食的氮肥,可能會使全球升溫2°C以內的氣候目標更難達成。

全世界用於生產糧食的氮肥,可能會使全球升溫2°C以內的氣候目標更難達成。照片來源:StateofIsrael(CC BY 2.0)

40年來人為的一氧化二氮排放增加了30%

全球碳計畫探討一氧化二氮(N2O)排放如何加劇氣候變遷,進行首次的全面性評估。研究結果發現,過去40年間,人類產生的一氧化二氮排放增加了30%,主要原因是農業使用。

肉類和奶製品需求成長也是重要推手,因為牲畜糞便會導致一氧化二氮排放,而且氮肥通常也用於生產動物飼料。

其中人類產生的一氧化二氮排放量成長極快的國家包括巴西、中國和印度。

一氧化二氮排放趨勢與氣候目標 兩者途徑不相容

一氧化二氮是能夠長期存在大氣中的溫室氣體,就100年為期來看,能耐是二氧化碳的300倍,僅次於二氧化碳和甲烷,是氣候變遷的第三大貢獻者。

氣體透過各種自然過程釋放到大氣中,包括土壤和海洋中微生物的活動。有些自然過程,包括平流層和對流層中的化學反應,則會減少一氧化二氮排放。

但是,人類活動也會導致一氧化二氮進入大氣。人類產生的一氧化二氮排放主要來自農業,化石燃料業和生質燃燒也會產生,但影響較小。

新研究探討2007至2016年所有排放一氧化二氮排放的方式,包括人類活動和自然過程,以計算出全球首個「一氧化二氮預算」。

奧本大學國際氣候與全球變遷研究中心主任田漢勤教授說,研究結果顯示,除非採取行動去抑制,否則人為一氧化二氮排放可能影響巴黎協定全球暖化遠低於2°C的目標。「研究結果最令人驚訝的發現是,當前一氧化二氮排放趨勢與實現巴黎協定氣候目標的可能途徑不相容。」

人為一氧化二氮排放 大部分來自農業中的氮肥

2007至2016年間,全球一氧化二氮排放量平均每年淨增加430萬噸,包括自然和人為來源產生的排放。

同一時間,人為一氧化二氮排放量成長30%,上升到每年730萬噸,其中一半以上來自提高農業產量的氮肥。

根據2019年政府間氣候變遷專門委員會(IPCC)發表的氣候變遷和土地報告,自1961年以來,全球農業肥料的使用量增加了9倍。

此外,肉類和奶製品需求不斷成長也是農業排放量增加的原因。「肉類和奶製品需求持續成長、牧場草地擴張,全球牲畜糞便生產和管理相關的一氧化二氮排放量也隨之大增。」

研究顯示,自1980年代以來,農業一氧化二氮排放量在東亞和南亞、南美和非洲的成長最快。同時,北美的農業一氧化二氮排放一直維持高水準,而歐洲的農業一氧化二氮排放則有小幅下降。

一氧化二氮排放量與氣候變遷可能情境比較

科學家也將目前一氧化二氮排放量與未來兩種氣候變遷可能情境中的排放量做比較,分別是「代表性濃度途徑(RCPs)」和「共享社會經濟途徑(SSPs)」。

下圖A顯示了全球一氧化二氮排放量與RCPs預測排放量相比。圖C是全球一氧化二氮濃度與RCPs預測濃度的比較。(在RCP2.6的假設情境下,全世界成功將全球暖化限制在2°C以下,RCP8.5則是排放量非常高的假設情境,在這個情境下,本世紀末溫度可能升高約4.3°C或更多。)

圖B顯示全球一氧化二氮排放量與SSPs的預測排放量的比較,而圖D顯示全球一氧化二氮濃度與SSPs的預測濃度的比較。(SSP3是各國在氣候行動上幾乎沒有合作的假設情境,SSP1是世界一同聚焦實現氣候目標的假設情境。)

圖上黑線是平均一氧化二氮排放量,藍色虛線是「自下而上」(bottom-up)估算值,以國家資料為基礎,黃色虛線是「自上而下」(top-down)估算值,以全球模型和衛星資料為基礎。

歷年與預測的一氧化二氮(N2O)排放(A,B)和濃度(C,D)趨勢圖。圖片來源:
Tian et al. (2020)

結果,目前一氧化二氮排放與高排放情境(RCP8.5)相符,並高過所有的SSPs情境。

研究作者、澳洲聯邦科學與工業研究組織(CSIRO)氣候研究中心首席科學家、全球碳計畫執行董事康納戴爾(Pep Canadell)博士說,這表示要將全球暖化限制在2°C以下,未來的幾十年需要迅速減少一氧化二氮排放。

「要種出能養活我們的大量糧食,全球糧食系統免不了會排放一些一氧化二氮,但是我們必須大幅提高使用效率來減少排放。」康納戴爾博士說。

未參與研究的阿伯丁大學植物和土壤科學系主任史密斯(Pete Smith)教授說,這表示全世界需要改變飲食習慣因應氣候變遷。 「我們必須找到更有效率的糧食生產方法,同時降低氮的用量和每單位產品的排放量。 我們還必須重新設計糧食體系,使其減少依賴肉類和奶製品等效率低下的糧食供應鏈,並顯著減少糧食浪費,在地球可負荷範圍內養活我們所有人。」

Nitrogen fertiliser use could ‘threaten global climate goals’ by DAISY DUNNE

The world’s use of nitrogen fertilisers for food production could threaten efforts to keep global warming below 2C above pre-industrial levels.

That is according to the Global Carbon Project’s first comprehensive assessment of how nitrous oxide (N2O) emissions are contributing to climate change.

Published in Nature, the results show that human-caused N2O emissions have increased by 30% over the past four decades – with the use of nitrogen fertilisers in agriculture playing a major role in the uptick.

A growing demand for meat and dairy products has also contributed to the surge. This is because livestock manure causes N2O emissions and nitrogen fertilisers are often used in the production of animal feed, the scientists say.

The countries with the fastest growing human-caused N2O emissions include Brazil, China and India, the research adds.

Potent pollutant

N2O is a long-lived greenhouse gas that is almost 300 times more potent than CO2 over a 100-year period. It is the third-largest contributor to climate change after CO2 and methane.

The gas is released into the atmosphere by various natural processes, including through the activity of microbes in soils and oceans. Other natural processes, including chemical reactions in the stratosphere and troposphere, cause a reduction in N2O emissions.

However, human activities can also cause N2O to be released into the atmosphere. Human-caused N2O emissions chiefly come from agriculture, with the fossil-fuel industry and biomass burning also contributing to a lesser degree.

The new assessment considered all the ways in which human activities and natural processes contributed to N2O emissions from 2007-16 in order to produce the first global “N2O budget”.

The findings show that, unless curbed, human-caused N2O emissions could threaten the Paris Agreement’s target of keeping global warming “well below” 2C, says lead author Prof Hanqin Tian, director of the International Center for Climate and Global Change Research at Auburn University in Alabama. He tells Carbon Brief:

“The most surprising result of the study was the finding that current trends in N2O emissions are not compatible with pathways consistent to achieve the climate goals of the Paris Agreement.”

First budget

The infographic below, which was produced by the Global Carbon project, summarises the findings. On the infographic, orange arrows show human-caused N2O emissions while green arrows show natural N2O emissions. A blue arrow indicates the reduction in N2O emissions provided by chemical reactions in the upper atmosphere (“atmospheric chemical sink”).

The infographic shows that global N2O emissions increased by a net 4.3m tonnes a year, on average, from 2007-16. This figure includes N2O emissions from both natural and human-caused sources.

In that time, human-caused N2O emissions rose to 7.3m tonnes per year. This is 30% higher than four decades ago, the study says.

More than half of human-caused N2O emissions come from agriculture. The main driver of these emissions are nitrogen fertilisers, which are routinely sprayed overfood crops in order to boost yields.

Fertiliser application on crops has increased nine-fold worldwide since 1961, according to a recent landmark report on land and climate change from the Intergovernmental Panel on Climate Change (IPCC) released in 2019.

However, a growing demand for meat and dairy products is also a driver of increasing agricultural emissions, the researchers say in their paper:

“Growing demand for meat and dairy products has substantially increased global N2O emissions from livestock manure production and management associated with the expansion of pastures and grazing land.”

The assessment shows that, since the 1980s, agricultural N2O emissions have been rising the fastest in East and South Asia, South America and Africa.

Meanwhile, agricultural N2O emissions in North America have stayed consistently high, while Europe has seen a small dip in its agricultural N2O emissions.
Outpaced

As part of their analysis, the scientists explored how current N2O emissions compare with those from the scenarios used to make future projections about climate change.

These include the “Representative Concentration Pathways” (RCPs) and the “Shared Socioeconomic Pathways” (SSPs). 

Chart A below shows how global N2O emissions compare with projected emissions from the RCPs. Chart C, meanwhile, shows how global concentrations of N2O compare to projected concentrations from the RCPs.

(RCP2.6 is a scenario where the world successfully limits global warming to below 2C, whereas RCP8.5 is a scenario of very high emissions, where temperatures could rise by around 4.3C or more by the end of the century.)

Chart B shows how global N2O emissions compare with projected emissions from the SSPs, while chart D shows how global concentrations of N2O compare to projected concentrations from the SSPs.

(SSP3 is a scenario where countries do little to cooperate on climate action, whereas SSP1 is a scenario where the world shifts its focus to meeting climate targets.)

On the charts, the black line shows average N2O emissions, whereas the blue line shows “bottom-up” estimates and the yellow line shows “top-down” estimates. (Bottom-up estimates are based on country inventory data, whereas top-up estimates are obtained from global models and satellite data.)

in order to limit global warming to below 2C, N2O emissions will need to be rapidly reduced in the coming decades, explains study author Dr Pep Canadell, chief research scientist at the Commonwealth Scientific and Industrial Research Organisation (CSIRO) Climate Research Centre in Australia and executive director of the Global Carbon Project. He tells Carbon Brief:

“The global food system will always leak some N2O given there are no alternatives to nitrogen fertiliser for growing so much of the food we eat. However, we must become much more efficient in the way we use it, which will lead to significant emission reductions.”

The findings reinforce the message that the world needs to change its eating habits in order to tackle climate change, says Prof Pete Smith, chair of plant and soil science at the University of Aberdeen, who was not involved in the research. He tells Carbon Brief:

“The study underlines that we must find more efficient ways of producing food, with lower nitrogen inputs and emissions per unit of product. But also, we must redesign our current food system so that it can feed us all within ‘planetary boundaries’ by reducing reliance on inefficient supply chains such as meat and dairy and by dramatically reducing food waste.”

※ 全文及圖片詳見:Carbon BriefCC BY-NC-ND 4.0

參考資料

氮肥
一氧化二氮
溫室氣體
升溫
動物飼料
農林漁牧業
國際新聞
氣候變遷

作者

姜唯

如果有一件事是重要的,如果能為孩子實現一個願望,那就是人類與大自然和諧共存。

林大利

於特有生物研究保育中心服務,小鳥和棲地是主要的研究對象。是龜毛的讀者,認為龜毛是探索世界的美德。

延伸閱讀

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※帶您來了解什麼是 USB CONNECTOR  ?

※自行創業缺乏曝光? 網頁設計幫您第一時間規劃公司的形象門面

※如何讓商品強力曝光呢? 網頁設計公司幫您建置最吸引人的網站,提高曝光率!

※綠能、環保無空污,成為電動車最新代名詞,目前市場使用率逐漸普及化

※廣告預算用在刀口上,台北網頁設計公司幫您達到更多曝光效益

※教你寫出一流的銷售文案?

極端天氣自然災害激增 專家籲強化預警和減災

摘錄自2020年10月13日中央社報導

專家今(13日)呼籲,隨著極端天氣與自然災害激增,世人應投注更多心力預測災害,同時儘早行動減輕災害的衝擊。

法新社報導,今天是國際減少災害風險日(International Day for Disaster Risk Reduction),10多個聯合國(UN)單位和金融機構藉最新報告釋出訊息,呼籲人們「(別問)未來天氣如何,該問的是天氣會造成什麼影響」,因為現實情況證明天氣愈來愈具毀滅力。

這份世界氣象組織(WMO)協調做成的報告表示,尤其近幾十年來,氣候變遷已推升這類災害的發生頻率、強度和嚴重性。

報告指出,2018年的風暴、旱澇與野火,曾使1億800萬人尋求國際人道體系協助。報告預估到2030年前,這個人數可能增加約5成。

氣候變遷
國際新聞
極端天氣
自然災害
減災

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※為什麼 USB CONNECTOR 是電子產業重要的元件?

網頁設計一頭霧水該從何著手呢? 台北網頁設計公司幫您輕鬆架站!

※台北網頁設計公司全省服務真心推薦

※想知道最厲害的網頁設計公司"嚨底家"!

※推薦評價好的iphone維修中心

吉力馬札羅山山坡大火 坦尚尼亞消防員連日撲救

摘錄自2020年10月13日中央社報導

東非國家坦尚尼亞官員表示,消防員連續第3天與吉力馬札羅山(Mount Kilimanjaro)山坡上的大火對抗,希望控制這座非洲第一高峰的火勢。

路透社報導,大火11日起於胡娜區(Whona),強風助長了火勢,官員表示,風勢今天已經減弱。胡娜區是使用曼達拉(Mandara)和霍倫坡(Horombo)兩條登山路線的登山客的休息中心。

坦尚尼亞國家公園管理局(TANAPA)官員謝魯特(Pascal Shelutete)向路透社表示,消防員與相關人員正努力控制火勢,並稱火勢已「幾乎獲遏止」。

氣候變遷
國際新聞
坦尚尼亞
吉力馬扎羅山
大火

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

USB CONNECTOR掌控什麼技術要點? 帶您認識其相關發展及效能

台北網頁設計公司這麼多該如何選擇?

※智慧手機時代的來臨,RWD網頁設計為架站首選

※評比南投搬家公司費用收費行情懶人包大公開

※回頭車貨運收費標準

反聖嬰現象形成 WMO:2020卻仍是最暖年份之一

摘錄自2020年10月30日自由時報報導

世界氣象組織(WMO)29日表示,今年太平洋已形成「中等到強」的反聖嬰現象(La Niña),盡管有降溫效應,但在氣候變遷推動下,全球氣溫仍將高於平常。

綜合外媒報導,WMO表示,反聖嬰現象「已經形成,預計將持續到明年,影響世界許多地區的溫度、降水和風暴型式」。該組織表示,這也可能導致今年異常活躍的颶風季節。今年的反聖嬰現象的強度預計為「中等到強」。根據該組織說法,最近一個短暫且較弱的反聖嬰現象發生於2017年11月到2018年4月,而上一次發生強度反聖嬰現象是2010到2011年。

WMO秘書長塔拉斯(Petteri Taalas)指出,反聖嬰現象通常會對全球溫度產生冷卻作用,但現在出現反聖嬰現象的年份甚至比過去出現聖嬰現象的年份更暖。因其大幅被溫室氣體散發到大氣中的熱量所抵銷。塔拉斯說,「因此,2020年仍將是有紀錄以來最溫暖的年份之一,2016至2020年將是有紀錄以來最溫暖的5年」。

氣候變遷
國際新聞
太平洋
聯合國
反聖嬰
全球暖化

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

網頁設計一頭霧水該從何著手呢? 台北網頁設計公司幫您輕鬆架站!

網頁設計公司推薦不同的風格,搶佔消費者視覺第一線

※想知道購買電動車哪裡補助最多?台中電動車補助資訊懶人包彙整

南投搬家公司費用,距離,噸數怎麼算?達人教你簡易估價知識!

※教你寫出一流的銷售文案?

※超省錢租車方案

巴西大沼澤10月火災 創1998年監測以來新高

摘錄自2020年10月30日中央社報導

巴西國家太空署(INPE)最新數據指出,10月中西部大沼澤再次創下自1998年太空署開始監測以來,當月起火點數目最多紀錄,10月1日至28日共記錄有2825個起火點。

根據巴西刑警和聯邦警察調查,跡象顯示中西部大沼澤的火災是人為過失引起,至少4處農牧場業主涉嫌蓄意放火,燒毀2萬5000公頃山林。

國家太空署指出,2020年1月至10月28日,大沼澤共記錄2萬1084個起火點,是大沼澤生物群系史上最嚴重的火災。大沼澤生物群系是世界上最大的淹水平原區,一旦不下雨,平原不會被淹沒,火勢容易擴散。大沼澤今年面臨47年來最嚴重乾旱,更有助於火勢蔓延。

除了大沼澤外,亞馬遜的火災數量今年也屢創歷史新高,1月至10月28日,亞馬遜生物群系共記錄9萬1873個起火點,此外,今年1月至9月在雨林累計的起火點也創下2010年以來新高。

根據聯邦政府本身的數據顯示,位於瑪瑙斯市和博阿維斯塔市兩市之間的羅賴諾波利斯(Rorainopolis),是今年亞馬遜地區發生最多森林火災的城市,如果加上鄰近兩個城市,累計燒毀面積超過2萬公頃。

氣候變遷
國際新聞
巴西
沼澤
森林大火

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

網頁設計一頭霧水該從何著手呢? 台北網頁設計公司幫您輕鬆架站!

網頁設計公司推薦不同的風格,搶佔消費者視覺第一線

※Google地圖已可更新顯示潭子電動車充電站設置地點!!

※廣告預算用在刀口上,台北網頁設計公司幫您達到更多曝光效益

※別再煩惱如何寫文案,掌握八大原則!

網頁設計最專業,超強功能平台可客製化

澳洲科學家發現巨型珊瑚礁 比帝國大廈還高

摘錄自2020年10月29日中央社報導

施密特海洋研究所(Schmidt Ocean Institute)本週表示,澳洲科學家在大堡礁發現一座獨立珊瑚礁,高度超越紐約帝國大廈和巴黎艾菲爾鐵塔,為120多年來首見。

這座「刀片狀」珊瑚礁將近500公尺高、1.5公里寬,頂端位於海平面下40公尺。由畢曼(Robin Beaman)博士率領的詹姆士庫克大學(James Cook University)科學家團隊20日在科研船福克爾號(Falkor)上,於大堡礁北方海床進行繪測作業時發現這座珊瑚礁。

科學家利用水下機器人SuBastian錄下他們探索這座新珊瑚礁的過程,一路上也在蒐集海洋樣本,之後將會存放在昆士蘭博物館(Queensland Museum)和昆士蘭熱帶博物館(Museum of Tropical Queensland)。

海洋
國際新聞
澳洲
珊瑚礁

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

網頁設計公司推薦不同的風格,搶佔消費者視覺第一線

※廣告預算用在刀口上,台北網頁設計公司幫您達到更多曝光效益

※自行創業缺乏曝光? 網頁設計幫您第一時間規劃公司的形象門面

南投搬家公司費用需注意的眉眉角角,別等搬了再說!

※教你寫出一流的銷售文案?

美新研究:野生吸血蝙蝠染病 自動保持社交距離

摘錄自2020年10月29日新頭殼報導

蝙蝠生病也懂得保持社交距離?!美國一項研究發現,野生的吸血蝙蝠(Desmodus rotundus)在被注入會生病的物質後,與其他蝙蝠或動物的接觸明顯變少,到等到牠們恢復健康,才會恢復原有的社交活動。

《行為生態學》(Behavioural Ecology)期刊發表一項最新研究《持續追蹤野生吸向蝙蝠染病對社交的影響》。研究人員是在2018年4月下旬,於伯利茲(Belize)Lamanai的一棵空心樹上,捕獲31隻成年的雌性吸血蝙蝠,其中16隻被注射脂多醣,讓蝙蝠出現發炎等生病症狀,而另外15隻則注射生理食鹽水對照。結果發現,在注射藥劑6小時內,被注射會生病物質的吸血蝙蝠與同伴互動數量,比注射食鹽水的蝙蝠少了約4隻。

研究發現,對照蝙蝠與每個對照蝙蝠有49%的接觸,但與生病蝙蝠只有35%的接觸。雖然之前有科學家在實驗室裡就發現此現象,但這是第一次在野外對野生蝙蝠進行研究,研究者得出結論表示,牠們真的會在生病時保持社交距離。且每隻生病蝙蝠的伴侶,陪伴時間平均也少了25分鐘,而病人本身則是睡得更多、移動得更少。

生物多樣性
國際新聞
蝙蝠

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※自行創業缺乏曝光? 網頁設計幫您第一時間規劃公司的形象門面

網頁設計一頭霧水該從何著手呢? 台北網頁設計公司幫您輕鬆架站!

※想知道最厲害的網頁設計公司"嚨底家"!

※別再煩惱如何寫文案,掌握八大原則!

※產品缺大量曝光嗎?你需要的是一流包裝設計!

最高齡原告已96歲 廣島黑雨判決 被告日本政府提上訴

文:宋瑞文(媽媽監督核電廠聯盟特約撰述)

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※廣告預算用在刀口上,台北網頁設計公司幫您達到更多曝光效益

※別再煩惱如何寫文案,掌握八大原則!

※教你寫出一流的銷售文案?

※超省錢租車方案

※廣告預算用在刀口上,台北網頁設計公司幫您達到更多曝光效益

※產品缺大量曝光嗎?你需要的是一流包裝設計!

「碳循環的沈睡巨人」 北極甲烷開始釋出 可能惡化氣候變遷

環境資訊中心綜合外電;姜唯 編譯;林大利 審校

本站聲明:網站內容來源環境資訊中心https://e-info.org.tw/,如有侵權,請聯繫我們,我們將及時處理

【其他文章推薦】

※別再煩惱如何寫文案,掌握八大原則!

網頁設計一頭霧水該從何著手呢? 台北網頁設計公司幫您輕鬆架站!

※超省錢租車方案

※教你寫出一流的銷售文案?

網頁設計最專業,超強功能平台可客製化

※產品缺大量曝光嗎?你需要的是一流包裝設計!