ICode9

精准搜索请尝试: 精确搜索
首页?>?bet356官网> 文章详细

Centosbet356体育下载_bet356客服邮箱_bet356官网 k8s

2019-09-04 17:08:02??阅读:57??来源: 互联网

标签:2docker?k8s?Centos?v1.14?mirrorgooglecontainers?docker?kube?bet356体育下载_bet356客服邮箱_bet356官网


### 一. bet356体育下载_bet356客服邮箱_bet356官网docker

1.bet356体育下载_bet356客服邮箱_bet356官网依赖包
```shell
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
```

2.设置阿里云镜像源
```shell
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
```
### 使用docker脚本一键bet356体育下载_bet356客服邮箱_bet356官网
```shell
curl -fsSL "https://get.docker.com/" | sh
systemctl enable --now docker
```
3.bet356体育下载_bet356客服邮箱_bet356官网Docker-CE

# Install Docker CE
## Set up the repository
### Install required packages.
```shell
yum install yum-utils device-mapper-persistent-data lvm2
```
### Add Docker repository.
```shell
yum-config-manager \
--add-repo \
https://download.docker.com/linux/centos/docker-ce.repo
```
### Install Docker CE.
```shell
yum update && yum install docker-ce-18.06.2.ce
```
### Create /etc/docker directory.
```shell
mkdir /etc/docker
```
### Setup daemon.
```shell
cat > /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

mkdir -p /etc/systemd/system/docker.service.d
```
### Restart Docker
```shell
systemctl daemon-reload
systemctl restart docker
```

### bet356体育下载_bet356客服邮箱_bet356官网k8s

在Dockerbet356体育下载_bet356客服邮箱_bet356官网完成的基础上,完成一下步骤

?

#### 使用阿里云镜像源
```shell
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
EOF
```
#### 关闭SElinux
```shell
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
```
#### bet356体育下载_bet356客服邮箱_bet356官网kubelet kubeadm kubectl
```shell
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable --now kubelet #
开机启动kubelet
```
#### centos7用户还需要设置路由:
```shell
yum install -y bridge-utils.x86_64
modprobe br_netfilter # 加载br_netfilter模块,使用lsmod查看开启的模块
cat < /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system # 重新加载所有配置文件

systemctl disable --now firewalld # 关闭防火墙
```
#### k8s要求关闭swap (qxl)
```shell
swapoff -a && sysctl -w vm.swappiness=0 # 关闭swap
sed -ri '/^[^#]*swap/s@^@#@' /etc/fstab # 取消开机挂载swap
```

#### 国外服务器
```shell
kubeadm config images pull #拉取集群所需镜像,这个需要翻墙
```

#### 国内服务器
```shell
kubeadm config images list #列出所需镜像,根据所需镜像bet356体育下载_bet356客服邮箱_bet356官网
```

#(不是一定是下面的,根据实际情况来选择版本)
#建议节点中也进行此操作bet356体育下载_bet356客服邮箱_bet356官网
# 根据所需镜像名字先拉取国内资源
```shell
docker pull mirrorgooglecontainers/kube-apiserver:v1.14.2
docker pull mirrorgooglecontainers/kube-controller-manager:v1.14.2
docker pull mirrorgooglecontainers/kube-scheduler:v1.14.2
docker pull mirrorgooglecontainers/kube-proxy:v1.14.2
docker pull mirrorgooglecontainers/pause:3.1
docker pull mirrorgooglecontainers/etcd:3.3.10
docker pull coredns/coredns:1.3.1 # 这个在mirrorgooglecontainers中没有

# 修改镜像tag
docker tag mirrorgooglecontainers/kube-apiserver:v1.14.2 k8s.gcr.io/kube-apiserver:v1.14.2
docker tag mirrorgooglecontainers/kube-controller-manager:v1.14.2 k8s.gcr.io/kube-controller-manager:v1.14.2
docker tag mirrorgooglecontainers/kube-scheduler:v1.14.2 k8s.gcr.io/kube-scheduler:v1.14.2
docker tag mirrorgooglecontainers/kube-proxy:v1.14.2 k8s.gcr.io/kube-proxy:v1.14.2
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag coredns/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1


# 把所需的镜像下载好,init的时候就不会再拉镜像,由于无法连接google镜像库导致出错

# 删除原来的镜像
docker rmi mirrorgooglecontainers/kube-apiserver:v1.14.2
docker rmi mirrorgooglecontainers/kube-controller-manager:v1.14.2
docker rmi mirrorgooglecontainers/kube-scheduler:v1.14.2
docker rmi mirrorgooglecontainers/kube-proxy:v1.14.2
docker rmi mirrorgooglecontainers/pause:3.1
docker rmi mirrorgooglecontainers/etcd:3.3.10
docker rmi coredns/coredns:1.3.1
```
```shell
cat >> kubeadm-config.yaml <<>
apiServer:
timeoutForControlPlane: 4m0s
extraArgs:
enable-admission-plugins: NamespaceLifecycle,LimitRanger,ServiceAccount,TaintNodesByCondition,Priority,DefaultTolerationSeconds,DefaultStorageClass,PersistentVolumeClaimResize,MutatingAdmissionWebhook,ValidatingAdmissionWebhook,ResourceQuota
runtime-config: "api/all=true"
apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
kubernetesVersion: stable
#下面HAPROXY_IPmaster的ip
controlPlaneEndpoint: "HAPROXY_IP:8443"
dns:
type: "CoreDNS"
networking:
dnsDomain: cluster.local
podSubnet: "10.244.0.0/16"
EOF
```
#### 初始化k8s
```shell
kubeadm reset --force #重置集群,初始化出错可以使用

#k8s初始化
#对hostname命名也有规范,报hostname不规范修改/etc/hostname,然后reboot就行了
kubeadm init --config=kubeadm-config.yaml --experimental-upload-certs
```
#### 初始化成功会生成token
```shell
#每个机器创建的master以下部分都不同,需要自己保存好,用于添加k8s节点
kubeadm join ip:8443 --token xxx \
--discovery-token-ca-cert-hash sha256:xxxx
```
#### 普通用户设置权限
```shell
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
```
#### bet356体育下载_bet356客服邮箱_bet356官网网络calico、flannel
```bash
# use calico cni
kubectl apply -f https://docs.projectcalico.org/v3.7/manifests/canal.yaml
# use standard flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.11.0/Documentation/kube-flannel.yml
```
#### node加入集群中
- node需要bet356体育下载_bet356客服邮箱_bet356官网docker和kubectl\kubecadm\kubelet,且版本与master的版本一致。
```bash
#主节点初始化生成的token,在节点中使用
kubeadm join master_ip:8443 --token xxx \
--discovery-token-ca-cert-hash sha256:xxxx

# 加入成功后查看master的nodes数目,稍等节点进行初始化,然后从notready到ready的状态。
```



标签:2docker,k8s,Centos,v1.14,mirrorgooglecontainers,docker,kube,bet356体育下载_bet356客服邮箱_bet356官网

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有