Kubeadm快速安装Kubernetes集群

Kubeadm快速安装Kubernetes集群

1.环境准备

注意:本文采用的是Google Cloud的主机,跳过了GFW个限制。在国内需要设置各种源才能根据本文步骤正常使用。

  • 准备主机
主机 配置 作用 IP
kubernetes-master1 Centos7,2核,8G内存,40G硬盘 集群master节点 34.73.166.205()/10.142.0.8()
kubernetes-node1 Centos7,2核,8G内存,40G硬盘 集群node节点 35.243.255.127()/10.142.0.9()
kubernetes-node2 Centos7,2核,8G内存,40G硬盘 集群node节点 34.74.128.163()/10.142.0.10()
kubernetes-node3 Centos7,2核,8G内存,40G硬盘 集群node节点 34.73.24.211()/10.142.0.11()

2.安装依赖

2.1 安装Docker

  • 卸载原来的Docker
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine
  • 安装相关依赖
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 && \
yum install -y --nogpgcheck cri-o
  • 添加镜像
yum-config-manager --add-repo=https://cbs.centos.org/repos/paas7-crio-311-candidate/x86_64/os/ && \
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo 
  • 添加配置
mkdir -p /etc/systemd/system/docker.service.d && \
sudo yum makecache fast && \
sudo yum -y install docker-ce && \
mkdir -p /etc/docker && 
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
  • 设置Docker服务
sudo systemctl start docker 
sudo systemctl enable docker 
sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-selinux \
                  docker-engine-selinux \
                  docker-engine

sudo yum install -y yum-utils device-mapper-persistent-data lvm2 && \
yum install -y --nogpgcheck cri-o && \

yum-config-manager --add-repo=https://cbs.centos.org/repos/paas7-crio-311-candidate/x86_64/os/ && \
sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo && \

mkdir -p /etc/systemd/system/docker.service.d && \
sudo yum makecache fast && \
sudo yum -y install docker-ce && \

mkdir -p /etc/docker && 
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

sudo systemctl start docker 
sudo systemctl enable docker 
#关闭防火墙
systemctl stop firewalld
#禁止防火墙开机启动
systemctl disable firewalld
#检查selinux
getenforce
Disabled
#端口检查
#关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld

2.2 安装

cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
exclude=kube*
EOF


setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes

systemctl enable --now kubelet

cat < kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta1
kind: InitConfiguration
controllerManager:
  horizontal-pod-autoscaler-use-rest-clients: "true"
  horizontal-pod-autoscaler-sync-period: "10s"
  node-monitor-grace-period: "10s"
apiServer:
  runtime-config: "api/all=true"
kubernetesVersion: "v1.14.1"
EOF



kubeadm init --config kubeadm.yaml

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

kubeadm join 10.142.0.8:6443 --token fif16e.z8wmqmyml2alnnxh \
    --discovery-token-ca-cert-hash sha256:3a98b9a304e77b9741ce02e43075c8f2b6df82cdcbe7f8590f760bf6657f4319  --ignore-preflight-errors=all

kubectl get node
kubectl describe node kubernetes-master
kubectl get pods -n kube-system

kubectl apply -f https://git.io/weave-kube-1.6
kubectl get pods -n kube-system

3.开始安装

a

func TwoSum(nums []int, target int) []int {
    if nums == nil || len(nums) < 2 {
        return []int{-1, -1}
    }
    res := []int{-1, -1}
    intMap := map[int]int{}
    for i := 0; i < len(nums); i++ {
        if _, ok := intMap[target-nums[i]]; ok {
            res[0] = intMap[target-nums[i]]
            res[1] = i
            break
        }
        intMap[nums[i]] = i
    }
    return res
}

package main

import (
       "github.com/gin-gonic/gin"
)
func main() {
router := gin.Default()
v1 := router.Group("/api/v1/todos")
 {
  v1.POST("/", createTodo)
  v1.GET("/", fetchAllTodo)
  v1.GET("/:id", fetchSingleTodo)
  v1.PUT("/:id", updateTodo)
  v1.DELETE("/:id", deleteTodo)
 }
 router.Run()
}
gitbook serve --config book.json . gitbook

  Reprint please specify: KYLE LIU Kubeadm快速安装Kubernetes集群

  TOC