Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cluster/etcd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ echo "Disable selinux and firewalld success!"
echo '============================================================'
echo '====================Downland etcd... ======================='
echo '============================================================'
ETCD_VERSION=v3.2.4
ETCD_VERSION=v3.2.7
echo "etcd version is $ETCD_VERSION"
ETCD_FILE=etcd-$ETCD_VERSION-linux-amd64
echo "etcd zip file is $ETCD_FILE"
Expand Down
33 changes: 29 additions & 4 deletions kubeadm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,42 @@

| 虚机名称 | IP |
| ------------- |:-------------:|
| master | 172.16.120.151|
| node01 | 172.16.120.152|
| master | 114.196.112.191 |
| node01 | 114.67.134.196|


kubeadm-master.sh和kubeadm-node.sh脚本采用kubeadm进行安装,采用国内镜像,安装简单快速。

vim /etc/hosts

114.196.112.191 k8s-master
114.67.134.196 k8s-node01

## master:

yum -y install vim java dos2unix

hostnamectl --static set-hostname k8s-master

将文件中的windows的换行符转换为linux中的换行符

dos2unix kubeadm-master.sh

## slave
yum -y install vim java dos2unix

hostnamectl --static set-hostname k8s-node01

将文件中的windows的换行符转换为linux中的换行符

dos2unix kubeadm-node.sh

# 2 master节点安装
```bash
sh kubeadm-master.sh 172.16.120.151
sh kubeadm-master.sh 114.196.112.191
```

# 3 node节点安装
```bash
sh kubeadm-node.sh 172.16.120.151
sh kubeadm-node.sh 114.67.134.196
```
9 changes: 7 additions & 2 deletions kubeadm/image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ set -o errexit
set -o nounset
set -o pipefail

KUBE_VERSION=v1.7.2
KUBE_VERSION=v1.7.5
KUBE_PAUSE_VERSION=3.0
ETCD_VERSION=3.0.17
DNS_VERSION=1.14.4
#需要手动导入flannel:${FLANNEL_VERSION}-amd64 到镜像仓库
#FLANNEL_VERSION=v0.8.0


GCR_URL=gcr.io/google_containers
ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/szss_k8s
ALIYUN_URL=registry.cn-beijing.aliyuncs.com/xin_k8s

images=(kube-proxy-amd64:${KUBE_VERSION}
kube-scheduler-amd64:${KUBE_VERSION}
Expand All @@ -27,6 +30,8 @@ k8s-dns-sidecar-amd64:${DNS_VERSION}
k8s-dns-kube-dns-amd64:${DNS_VERSION}
k8s-dns-dnsmasq-nanny-amd64:${DNS_VERSION})

#flannel:${FLANNEL_VERSION}-amd64


for imageName in ${images[@]} ; do
docker pull $GCR_URL/$imageName
Expand Down
55 changes: 33 additions & 22 deletions kubeadm/kubeadm-master.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ set -o pipefail

MASTER_ADDRESS=${1:-"127.0.0.1"}
KUBE_TOKEN=${2:-"863f67.19babbff7bfe8543"}
DOCKER_MIRRORS=${3:-"https://5md0553g.mirror.aliyuncs.com"}
KUBE_VERSION=1.7.2
DOCKER_MIRRORS=${3:-"https://34wskgqy.mirror.aliyuncs.com"}
KUBE_VERSION=1.7.5
KUBE_PAUSE_VERSION=3.0
KUBE_CNI_VERSION=0.5.1
ETCD_VERSION=3.0.17
FLANNEL_VERSION=v0.8.0
ALIYUN_URL=registry.cn-beijing.aliyuncs.com/xin_k8s


echo '============================================================'
echo '====================Disable selinux and firewalld...========'
echo '============================================================'

if [ $(getenforce) = "Enabled" ]; then
setenforce 0
fi
Expand All @@ -26,6 +29,8 @@ systemctl stop firewalld

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

modprobe br_netfilter

cat >> /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
Expand All @@ -47,26 +52,13 @@ gpgcheck=0
EOF
echo "Add docker yum repo success!"

echo '============================================================'
echo '====================Add kubernetes yum repo...=============='
echo '============================================================'
#kubernetes yum源
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
echo "Add kubernetes yum repo success!"

echo '============================================================'
echo '====================Install docker...======================='
echo '============================================================'
#查看docker版本
#yum list docker-engine showduplicates
#安装docker
yum install -y docker-engine-1.12.6-1.el7.centos.x86_64
yum install -y docker

echo "Install docker success!"

Expand All @@ -79,8 +71,24 @@ cat > /etc/docker/daemon.json <<EOF
"registry-mirrors": ["${DOCKER_MIRRORS}"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
echo "Config docker success!"

echo '============================================================'
echo '====================Add kubernetes yum repo...=============='
echo '============================================================'
#kubernetes yum源
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
echo "Add kubernetes yum repo success!"


echo '============================================================'
echo '====Install kubernetes-cni、kubelet、kubectl、kubeadm...====='
echo '============================================================'
Expand All @@ -97,12 +105,15 @@ echo "Install kubernetes success!"
echo '============================================================'
echo '===================Config kubelet...========================'
echo '============================================================'
sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
#sed -i '/KUBELET_NETWORK_ARGS=--network-plugin=cni/d' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
#sed -i 's/$KUBELET_NETWORK_ARGS//g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf


echo "config --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/szss_k8s/pause-amd64:${KUBE_PAUSE_VERSION}"
echo "config --pod-infra-container-image=${ALIYUN_URL}/pause-amd64:${KUBE_PAUSE_VERSION}"
cat > /etc/systemd/system/kubelet.service.d/20-pod-infra-image.conf <<EOF
[Service]
Environment="KUBELET_EXTRA_ARGS=--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/szss_k8s/pause-amd64:${KUBE_PAUSE_VERSION}"
Environment="KUBELET_EXTRA_ARGS=--pod-infra-container-image=${ALIYUN_URL}/pause-amd64:${KUBE_PAUSE_VERSION}"
EOF

echo "Config kubelet success!"
Expand All @@ -117,11 +128,11 @@ systemctl start kubelet
echo "The docker and kubelet services started"

echo "init kubernetes master..."
export KUBE_REPO_PREFIX="registry.cn-hangzhou.aliyuncs.com/szss_k8s"
export KUBE_ETCD_IMAGE="registry.cn-hangzhou.aliyuncs.com/szss_k8s/etcd-amd64:${ETCD_VERSION}"
export KUBE_REPO_PREFIX="${ALIYUN_URL}"
export KUBE_ETCD_IMAGE="${ALIYUN_URL}/etcd-amd64:${ETCD_VERSION}"
#--pod-network-cidr指定IP段需要和kube-flannel.yml文件中配置的一致
#--token指定token,token的格式为<6 character string>.<16 character string>,指定token后可以通过cat /etc/kubernetes/pki/tokens.csv查看
kubeadm init --apiserver-advertise-address=${MASTER_ADDRESS} --kubernetes-version=v${KUBE_VERSION} --token=${KUBE_TOKEN} --pod-network-cidr=10.244.0.0/12
kubeadm init --apiserver-advertise-address=${MASTER_ADDRESS} --kubernetes-version=v${KUBE_VERSION} --token=${KUBE_TOKEN} --pod-network-cidr=10.244.0.0/12 --skip-preflight-checks

#查看token的命令
echo "you can use this order to query the token: kubeadm token list"
Expand Down
23 changes: 13 additions & 10 deletions kubeadm/kubeadm-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ set -o pipefail

MASTER_ADDRESS=${1:-"127.0.0.1"}
KUBE_TOKEN=${2:-"863f67.19babbff7bfe8543"}
DOCKER_MIRRORS=${3:-"https://5md0553g.mirror.aliyuncs.com"}
KUBE_VERSION=1.7.2
DOCKER_MIRRORS=${3:-"https://34wskgqy.mirror.aliyuncs.com"}
KUBE_VERSION=1.7.5
KUBE_PAUSE_VERSION=3.0
KUBE_CNI_VERSION=0.5.1
ETCD_VERSION=3.0.17
ALIYUN_URL=registry.cn-beijing.aliyuncs.com/xin_k8s


echo '============================================================'
echo '====================Disable selinux and firewalld...========'
Expand All @@ -25,6 +27,7 @@ systemctl stop firewalld

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

modprobe br_netfilter
cat >> /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
Expand Down Expand Up @@ -65,7 +68,7 @@ echo '============================================================'
#查看docker版本
#yum list docker-engine showduplicates
#安装docker
yum install -y docker-engine-1.12.6-1.el7.centos.x86_64
yum install -y docker

echo "Install docker success!"

Expand All @@ -89,19 +92,20 @@ echo '============================================================'
#yum list kubelet showduplicates
#yum list kubectl showduplicates
#安装kubelet
yum install -y kubernetes-cni-${KUBE_CNI_VERSION}-0.x86_64 kubelet-${KUBE_VERSION}-0.x86_64 kubectl-${KUBE_VERSION}-0.x86_64 kubeadm-${KUBE_VERSION}-0.x86_64
yum install -y kubernetes-cni-${KUBE_CNI_VERSION}-0.x86_64 kubelet-${KUBE_VERSION}-0.x86_64 kubectl-${KUBE_VERSION}-0.x86_64 kubeadm-${KUBE_VERSION}-0.x86_64

echo "Install kubernetes success!"

echo '============================================================'
echo '===================Config kubelet...========================'
echo '============================================================'
sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
# 1.7.5 的版本默认都是systemd
# sed -i 's/cgroup-driver=systemd/cgroup-driver=cgroupfs/g' /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

echo "config --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/szss_k8s/pause-amd64:${KUBE_PAUSE_VERSION}"
cat > /etc/systemd/system/kubelet.service.d/20-pod-infra-image.conf <<EOF
[Service]
Environment="KUBELET_EXTRA_ARGS=--pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/szss_k8s/pause-amd64:${KUBE_PAUSE_VERSION}"
Environment="KUBELET_EXTRA_ARGS=--pod-infra-container-image=${ALIYUN_URL}/pause-amd64:${KUBE_PAUSE_VERSION}"
EOF

echo "Config kubelet success!"
Expand All @@ -118,8 +122,7 @@ echo "The docker and kubelet services started"
echo '============================================================'
echo '==============Join kubernetes cluster...===================='
echo '============================================================'
export KUBE_REPO_PREFIX="registry.cn-hangzhou.aliyuncs.com/szss_k8s"
export KUBE_ETCD_IMAGE="registry.cn-hangzhou.aliyuncs.com/szss_k8s/etcd-amd64:${ETCD_VERSION}"
export KUBE_REPO_PREFIX="${ALIYUN_URL}"
export KUBE_ETCD_IMAGE="${ALIYUN_URL}/etcd-amd64:${ETCD_VERSION}"
kubeadm join --token ${KUBE_TOKEN} ${MASTER_ADDRESS}:6443 --skip-preflight-checks
echo "Join kubernetes cluster success!"

echo "Join kubernetes cluster success!"