Fork me on Gitee

HDIS-Framework

fork star

HDIS-Framework是一个基于SpringBoot、Kubernetes、阿里云服务,编写的一个用于支撑微服务的极速开发框架。

其文档详尽,Demo全面,设计合理,开箱即用,节省开发时间,提升开发效率。

配套的docker、Kubernetes教程已踩过各种坑,让你的微服务无障碍的顺畅运行起来。

HDIS与Kubernetes或SpringCloud配合使用,能达到最佳效果。

K8S运维笔记-使用kubeadm安装K8S

安装kubeadm

更新安装源

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

配置

setenforce 0
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

安装

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable kubelet && systemctl start kubelet

安装Master

前提条件

需要安装docker
需要安装kubeadm
至少需要2核2G的机器

准备镜像

查看镜像所需包

kubeadm config images list

1.11.2版本需要如下包

k8s.gcr.io/kube-apiserver-amd64:v1.11.2
k8s.gcr.io/kube-controller-manager-amd64:v1.11.2
k8s.gcr.io/kube-scheduler-amd64:v1.11.2
k8s.gcr.io/kube-proxy-amd64:v1.11.2
k8s.gcr.io/pause:3.1
k8s.gcr.io/etcd-amd64:3.2.18
k8s.gcr.io/coredns:1.1.3
quay.io/calico/typha:v0.7.4
quay.io/calico/node:v3.1.3
quay.io/calico/cni:v3.1.3

拉取镜像

docker pull mirrorgooglecontainers/kube-apiserver-amd64:v1.11.2
docker pull mirrorgooglecontainers/kube-controller-manager-amd64:v1.11.2
docker pull mirrorgooglecontainers/kube-scheduler-amd64:v1.11.2
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.11.2
docker pull mirrorgooglecontainers/pause-amd64:3.1
docker pull mirrorgooglecontainers/etcd-amd64:3.2.18
docker pull coredns/coredns:1.1.3
docker pull calico/typha:v0.7.4
docker pull calico/node:v3.1.3
docker pull calico/cni:v3.1.3

镜像更名

docker tag mirrorgooglecontainers/kube-apiserver-amd64:v1.11.2 k8s.gcr.io/kube-apiserver-amd64:v1.11.2
docker tag mirrorgooglecontainers/kube-controller-manager-amd64:v1.11.2 k8s.gcr.io/kube-controller-manager-amd64:v1.11.2
docker tag mirrorgooglecontainers/kube-scheduler-amd64:v1.11.2 k8s.gcr.io/kube-scheduler-amd64:v1.11.2
docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.11.2 k8s.gcr.io/kube-proxy-amd64:v1.11.2
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd-amd64:3.2.18 k8s.gcr.io/etcd-amd64:3.2.18
docker tag coredns/coredns:1.1.3 k8s.gcr.io/coredns:1.1.3
docker tag calico/typha:v0.7.4 quay.io/calico/typha:v0.7.4
docker tag calico/node:v3.1.3 quay.io/calico/node:v3.1.3
docker tag calico/cni:v3.1.3 quay.io/calico/cni:v3.1.3

删除旧镜像

docker rmi mirrorgooglecontainers/kube-apiserver-amd64:v1.11.2
docker rmi mirrorgooglecontainers/kube-controller-manager-amd64:v1.11.2
docker rmi mirrorgooglecontainers/kube-scheduler-amd64:v1.11.2
docker rmi mirrorgooglecontainers/kube-proxy-amd64:v1.11.2
docker rmi mirrorgooglecontainers/pause-amd64:3.1
docker rmi mirrorgooglecontainers/etcd-amd64:3.2.18
docker rmi coredns/coredns:1.1.3
docker rmi calico/typha:v0.7.4
docker rmi calico/node:v3.1.3
docker rmi calico/cni:v3.1.3

安装

–pod-network-cidr 指定安装Calico网络
–kubernetes-version=1.11.2 指定安装k8s具体版本,指定后将不用上网扫描

kubeadm init --pod-network-cidr=192.168.0.0/16 --kubernetes-version=1.11.2

配置kubectl

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

配置网络

kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.1/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml

配置端口范围

vi /etc/kubernetes/manifests/kube-apiserver.yaml
--service-node-port-range=1-65535

失败处理

查询日志,查明原因
journalctl -f -u kubelet
master上重置节点

kubeadm reset

安装Node

前提条件

需要安装docker
需要安装kubeadm
至少需要2核2G的机器

准备镜像

镜像下载地址:https://hub.docker.com/u/mirrorgooglecontainers/
1.11.2版本需要如下包,可使用阿里云容器镜像服务在海外下载镜像

k8s.gcr.io/kube-proxy-amd64:v1.11.2
k8s.gcr.io/pause:3.1

拉取镜像

docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.11.2
docker pull mirrorgooglecontainers/pause-amd64:3.1

镜像更名

docker tag mirrorgooglecontainers/kube-proxy-amd64:v1.11.2 k8s.gcr.io/kube-proxy-amd64:v1.11.2
docker tag mirrorgooglecontainers/pause-amd64:3.1 k8s.gcr.io/pause:3.1

删除旧镜像

docker rmi mirrorgooglecontainers/kube-proxy-amd64:v1.11.2
docker rmi mirrorgooglecontainers/pause-amd64:3.1

在master节点上查看join命令需要的值

token

kubeadm token list

hash

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

master-ip:master-port

cat /etc/kubernetes/kubelet.conf

安装

kubeadm join --token <token> <master-ip>:<master-port> --discovery-token-ca-cert-hash sha256:<hash>
kubeadm join --token 6w4krr.0jecbasna9n2wyrs 172.16.240.208:6443 --discovery-token-ca-cert-hash sha256:e7ca4b7e85a8b1802e32ea2438bfe9fbff35c6f31134d77ceaa0d241ec2fb315

配置kubectl

mkdir -p $HOME/.kube

复制config文件到.kube文件夹

chown $(id -u):$(id -g) $HOME/.kube/config

失败处理

查询日志,查明原因
journalctl -f -u kubelet
删除node节点

kubectl drain <node name> --delete-local-data --force --ignore-daemonsets
kubectl delete node <node name>

node上重置节点

kubeadm reset
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐