学习

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# install docker

# registry.access.redhat.com/rhel7/pod-infrastructure:latest
# gcr.io/google_containers/pause:3.1
# gcr.io/google_containers/pause-amd64:3.0

# k8s.gcr.io/pause-amd64:3.1

# --pod-infra-container-image
#	The image whose network/ipc namespaces containers in each pod will use. This docker-specific flag only works when container-runtime is set to docker. (default "k8s.gcr.io/pause:3.1")

curl -s https://zhangguanzhang.github.io/bash/pull.sh | bash -s -- gcr.io/google_containers/pause:3.1
curl -s https://zhangguanzhang.github.io/bash/pull.sh | bash -s -- k8s.gcr.io/pause:3.1

# curl -sSL https://git.io/getgcr | bash -s gcr.io/google_containers/pause-amd64:3.1
# curl -sSL https://git.io/getgcr | bash -s "k8s.gcr.io/kube-{apiserver,controller-manager,proxy,scheduler}:v1.15.1"

#docker image pull registry.cn-shenzhen.aliyuncs.com/cookcodeblog/pause-amd64:3.1
#docker image tag registry.cn-shenzhen.aliyuncs.com/cookcodeblog/pause-amd64:3.1 k8s.gcr.io/pause-amd64:3.1
#docker image rmi registry.cn-shenzhen.aliyuncs.com/cookcodeblog/pause-amd64:3.1

##################
ii="kube-apiserver:v1.16.2 kube-controller-manager:v1.16.2 kube-scheduler:v1.16.2 kube-proxy:v1.16.2 pause:3.1 etcd:3.3.15-0 coredns:1.6.2 metrics-server-amd64:v0.3.3 echoserver:1.10"
for i in $ii; do
    echo $i
    docker image pull gcr.azk8s.cn/google_containers/$i;
    docker image tag gcr.azk8s.cn/google_containers/$i k8s.gcr.io/$i;
    docker image rm gcr.azk8s.cn/google_containers/$i;
done
docker image list |grep gcr

# gcr.io/kuar-demo/kuard-amd64:blue
# gcr.io/kuar-demo/kuard-amd64:green

docker image pull gcr.azk8s.cn/kuar-demo/kuard-amd64:blue;
docker image pull gcr.azk8s.cn/kuar-demo/kuard-amd64:green;
docker image tag gcr.azk8s.cn/kuar-demo/kuard-amd64:blue gcr.io/kuar-demo/kuard-amd64:blue;
docker image tag gcr.azk8s.cn/kuar-demo/kuard-amd64:green gcr.io/kuar-demo/kuard-amd64:green;
docker image rm gcr.azk8s.cn/kuar-demo/kuard-amd64:green;
docker image rm gcr.azk8s.cn/kuar-demo/kuard-amd64:blue;



##########


wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

# yum list docker-ce --showduplicates | sort -r
yum -y install docker-ce-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker

# install kubelet、kubeadm、kubectl

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
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

yum install -y kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0
systemctl enable kubelet
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# pull images 
https://github.com/cookcodeblog/k8s-deploy/blob/master/kubeadm/04_pull_kubernetes_images_from_aliyun.sh
# kubeadm config images pull --config=init-config.yaml

TOKEN_ID=$(openssl rand -hex 3)
TOKEN_SECRET=$(openssl rand -hex 8)
token=$TOKEN_ID.$TOKEN_SECRET

#echo $token
#kubeadm init --config=init-config.yaml

kubeadm init --token=$token \
--kubernetes-version $(kubeadm version -o short) \
--apiserver-advertise-address=192.168.31.61 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16


certhash=`openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'`

echo "kubeadm join 172.17.0.27:6443 --token $token --discovery-token-ca-cert-hash sha256:$certhash"


sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf


kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

brctl delbr cni0
ip link delete flannel.1

参考