• kubenetes_V1.14.0 安装部署


    k8s的安装有多种方式,如yum安装,kubeadm安装,kubemini安装,二进制安装(生产环境多采用此方式精确控制安装)等。本文是入门系列验证,之前进行过yum安装,可以查看文章《k8s入门系列之集群yum安装篇》   。这里进行kubeadm安装一次了解安装过程,真正的学习、测试环境和生产环境都不建议此方法,都建议yum安装或者二进制安装,这样才可以详细了解到k8s的工作原理和工作过程

    平台 :CentOS Linux release 7.6.1810 (Core) 

    master: 192.168.122.220
    node1:  192.168.122.221
    node2:  192.168.122.222

    一,三台机器前期工作准备
    1,关闭防火墙服务,避免与docker容器的防火墙规则冲突。
    systemctl stop firewalld
    systemctl disable firewalld

    2,关闭selinux:
    修改/etc/selinux/config为SELINUX=disabled
    重启后配置生效。不建议临时关闭(setenfore 0),防止机器重启失效。

    3,关闭swap:
    临时关闭:

    1. swapoff -a

    永久关闭:

    1. sed -i 's/.*swap.*/#&/' /etc/fstab

    4,host定向,将机器内部主机名通信打通:
    vi /etc/hosts

    192.168.122.220 master
    192.168.122.221 node01
    192.168.122.222 node02

    5,master机器设置免密钥登陆其他两个node

    1. ssh-keygen #生成密钥对
    2. cd /root/.ssh/
    3. ssh-copy-id -i id_rsa.pub node01
    4. ssh-copy-id -i id_rsa.pub node02

    6,配置ntp:

    1. yum install ntpdate -y
    2. systemctl enable ntpdate.service
    3. systemctl start ntpdate.service
    4. 临时同步:ntpdate time7.aliyun.com
    5. 设置任务计划crontab -e
    6. */30 * * * * /usr/sbin/ntpdate time7.aliyun.com >/dev/null 2>&1

    7,设置内核,建议安装标准系统初始化进行(部分厂商的机器已经进行了默认参数优化)

    1. echo "* soft nofile 65536">> /etc/security/limits.conf
    2. echo "* hard nofile 65536" >> /etc/security/limits.conf
    3. echo "* soft nproc 65536" >> /etc/security/limits.conf
    4. echo "* hard nproc 65536" >> /etc/security/limits.conf
    5. echo "* soft memlock unlimited" >> /etc/security/limits.conf
    6. echo "* hard memlock unlimited" >> /etc/security/limits.conf

    修正转发:

    1. modprobe br_netfilter
    2. cat < < EOF > /etc/sysctl.d/k8s.conf
    3. net.bridge.bridge-nf-call-ip6tables = 1
    4. net.bridge.bridge-nf-call-iptables = 1
    5. EOF
    6. sysctl -p /etc/sysctl.d/k8s.conf

    8,设置yum源

    1. epel源:
    2. yum install -y epel-release
    3.  
    4. #kubenetes yum源 ,采用阿里云
    5. cat &lt; /etc/yum.repos.d/kubernetes.repo
    6. [kubernetes]
    7. name=Kubernetes
    8. baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
    9. enabled=1
    10. gpgcheck=0
    11. repo_gpgcheck=0
    12. gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
    13. EOF
    14. ---------------------
    15. #docker yum源 采用阿里云
    16. wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    17. yum clean all &amp;&amp; yum makecache fast

    9,安装依赖包

    1. yum install -y yum-utils device-mapper-persistent-data lvm2 net-tools conntrack-tools wget vim ntpdate libseccomp libtool-ltdl

    二,进行kubeadm 集群安装部署
    1,组件安装
    master节点安装etcd:

      1. yum install etcd -y
      2. systemctl enable etcd

    由于采用外部 etcd,所以要在 master 节点安装 etcd服务,这里也是etcd是单节点。不管是etcd集群还是单机,或者是 http, https都可以,只要在 kubeadm 中配置好就行。

    master和其他node:

    1. yum install docker-ce kubelet kubeadm kubectl ipvsadm -y
    2. systemctl restart kubelet
    3. systemctl restart docker
    4. systemctl enable kubelet
    5. systemctl enable docker

    2,kubeadm安装配置 kubenetes 1.12.2集群

    1. kubeadm init --kubernetes-version=v1.12.2 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=10.1.14.12

    这里由于我的虚拟机都设置了科学上网,所以可以直接去下载。 没有配置科学上网的,建议采用阿里云的镜像下载后更改tag处理再kubeadm安装。
    安装完信息如下,则说明初始化成功:

     1 [root@master docker]# kubeadm init  --kubernetes-version=v1.12.2 --pod-network-cidr=10.244.0.0/16  --apiserver-advertise-address=10.1.14.12
     2 [init] using Kubernetes version: v1.12.2
     3 [preflight] running pre-flight checks
     4         [WARNING Service-Docker]: docker service is not enabled, please run 'systemctl enable docker.service'
     5 [preflight/images] Pulling images required for setting up a Kubernetes cluster
     6 [preflight/images] This might take a minute or two, depending on the speed of your internet connection
     7 [preflight/images] You can also perform this action in beforehand using 'kubeadm config images pull'
     8 [kubelet] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env"
     9 [kubelet] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml"
    10 [preflight] Activating the kubelet service
    11 [certificates] Generated front-proxy-ca certificate and key.
    12 [certificates] Generated front-proxy-client certificate and key.
    13 [certificates] Generated ca certificate and key.
    14 [certificates] Generated apiserver certificate and key.
    15 [certificates] apiserver serving cert is signed for DNS names [master kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local] and IPs [10.96.0.1 10.1.14.12]
    16 [certificates] Generated apiserver-kubelet-client certificate and key.
    17 [certificates] Generated etcd/ca certificate and key.
    18 [certificates] Generated etcd/peer certificate and key.
    19 [certificates] etcd/peer serving cert is signed for DNS names [master localhost] and IPs [10.1.14.12 127.0.0.1 ::1]
    20 [certificates] Generated etcd/healthcheck-client certificate and key.
    21 [certificates] Generated apiserver-etcd-client certificate and key.
    22 [certificates] Generated etcd/server certificate and key.
    23 [certificates] etcd/server serving cert is signed for DNS names [master localhost] and IPs [127.0.0.1 ::1]
    24 [certificates] valid certificates and keys now exist in "/etc/kubernetes/pki"
    25 [certificates] Generated sa key and public key.
    26 [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/admin.conf"
    27 [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/kubelet.conf"
    28 [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/controller-manager.conf"
    29 [kubeconfig] Wrote KubeConfig file to disk: "/etc/kubernetes/scheduler.conf"
    30 [controlplane] wrote Static Pod manifest for component kube-apiserver to "/etc/kubernetes/manifests/kube-apiserver.yaml"
    31 [controlplane] wrote Static Pod manifest for component kube-controller-manager to "/etc/kubernetes/manifests/kube-controller-manager.yaml"
    32 [controlplane] wrote Static Pod manifest for component kube-scheduler to "/etc/kubernetes/manifests/kube-scheduler.yaml"
    33 [etcd] Wrote Static Pod manifest for a local etcd instance to "/etc/kubernetes/manifests/etcd.yaml"
    34 [init] waiting for the kubelet to boot up the control plane as Static Pods from directory "/etc/kubernetes/manifests" 
    35 [init] this might take a minute or longer if the control plane images have to be pulled
    36 [apiclient] All control plane components are healthy after 39.007740 seconds
    37 [uploadconfig] storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace
    38 [kubelet] Creating a ConfigMap "kubelet-config-1.12" in namespace kube-system with the configuration for the kubelets in the cluster
    39 [markmaster] Marking the node master as master by adding the label "node-role.kubernetes.io/master=''"
    40 [markmaster] Marking the node master as master by adding the taints [node-role.kubernetes.io/master:NoSchedule]
    41 [patchnode] Uploading the CRI Socket information "/var/run/dockershim.sock" to the Node API object "master" as an annotation
    42 [bootstraptoken] using token: wzh9es.gaz6xloz7omrswvs
    43 [bootstraptoken] configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials
    44 [bootstraptoken] configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token
    45 [bootstraptoken] configured RBAC rules to allow certificate rotation for all node client certificates in the cluster
    46 [bootstraptoken] creating the "cluster-info" ConfigMap in the "kube-public" namespace
    47 [addons] Applied essential addon: CoreDNS
    48 [addons] Applied essential addon: kube-proxy
    49  
    50 Your Kubernetes master has initialized successfully!
    51  
    52 To start using your cluster, you need to run the following as a regular user:
    53  
    54   mkdir -p $HOME/.kube
    55   sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
    56   sudo chown $(id -u):$(id -g) $HOME/.kube/config
    57  
    58 You should now deploy a pod network to the cluster.
    59 Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
    60   https://kubernetes.io/docs/concepts/cluster-administration/addons/
    61  
    62 You can now join any number of machines by running the following on each node
    63 as root:
    64  
    65 kubeadm join 192.168.122.220:6443 --token ry7iaa.ysxah86uu9erif9v 
    66     --discovery-token-ca-cert-hash sha256:9b7b17fd3da2e16925a3a729a362d04b19c0a3d73a2f2f1b13d44134db3166af
    View Code

    里边的信息量很大,可以多仔细看两遍,其中最后将node加入集群的命令可以记录一下。

    按照提示,在开始使用集群之前,执行如下命令(提示信息直接贴过来即可):

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

    配置完毕以后查看node信息:

    1. [root@master ~]# kubectl get node
    2. NAME STATUS ROLES AGE VERSION
    3. master NotReady master 8m5s v1.12.2

    原因是flannel没有配置,配置flannel:

    1. kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
    2. kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/k8s-manifests/kube-flannel-rbac.yml

    重新查看:

    1. [root@master ~]# kubectl get node
    2. NAME STATUS ROLES AGE VERSION
    3. master Ready master 16m v1.12.2
    4. [root@master ~]# kubectl get pods --all-namespaces
    5. NAMESPACE NAME READY STATUS RESTARTS AGE
    6. kube-system coredns-576cbf47c7-ftvc8 1/1 Running 0 15m
    7. kube-system coredns-576cbf47c7-rtm6f 1/1 Running 0 15m
    8. kube-system etcd-master 1/1 Running 0 75s
    9. kube-system kube-apiserver-master 1/1 Running 0 66s
    10. kube-system kube-controller-manager-master 1/1 Running 0 77s
    11. kube-system kube-flannel-ds-amd64-488hv 1/1 Running 0 99s
    12. kube-system kube-proxy-d4v7j 1/1 Running 0 15m
    13. kube-system kube-scheduler-master 1/1 Running 0 77s
    14. [root@master ~]# kubectl get cs
    15. NAME STATUS MESSAGE ERROR
    16. scheduler Healthy ok
    17. controller-manager Healthy ok
    18. etcd-0 Healthy {"health": "true"}

    3,node节点配置
    node01和node02分别执行之前的命令提示,将node01 node02加入到集群:

    systemctl stop firewalld
    systemctl disable firewalld
    setenforce 0
    swapoff -a
    sed -i 's/.*swap.*/#&/' /etc/fstab

    yum install ntpdate -y
    systemctl enable ntpdate.service
    systemctl start ntpdate.service

    echo "* soft nofile 65536">> /etc/security/limits.conf
    echo "* hard nofile 65536" >> /etc/security/limits.conf
    echo "* soft nproc 65536" >> /etc/security/limits.conf
    echo "* hard nproc 65536" >> /etc/security/limits.conf
    echo "* soft memlock unlimited" >> /etc/security/limits.conf
    echo "* hard memlock unlimited" >> /etc/security/limits.conf

    cat << EOF > /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF
    sysctl -p /etc/sysctl.d/k8s.conf
    yum install docker-ce kubelet kubeadm kubectl ipvsadm -y
    yum install -y epel-release

    cd /etc/yum.repos.d/

    wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

    yum install -y yum-utils device-mapper-persistent-data lvm2 net-tools conntrack-tools wget vim ntpdate libseccomp libtool-ltdl
    yum install etcd -y
    systemctl enable etcd
    yum install docker-ce kubelet kubeadm kubectl ipvsadm -y
    systemctl restart kubelet
    systemctl restart docker
    systemctl enable kubelet
    systemctl enable docker

    kubeadm join 192.168.122.220:6443 --token ry7iaa.ysxah86uu9erif9v     --discovery-token-ca-cert-hash sha256:9b7b17fd3da2e16925a3a729a362d04b19c0a3d73a2f2f1b13d44134db3166af

  • 相关阅读:
    centos7安装Oracle12c
    Spring框架学习总结(上)
    如何教会女友递归算法?
    别翻了,这篇文章就是要让你入门java多线程!
    【从今天开始好好学数据结构04】程序员你心中就没点“树”吗?
    【从今天开始好好学数据结构03】链表
    【从今天开始好好学数据结构02】栈与队列
    别翻了,这篇文章绝对让你深刻理解java类的加载以及ClassLoader源码分析【JVM篇二】
    深入理解java继承从“我爸是李刚”讲起
    深入理解java多态没有烤山药的存在,java就不香了吗?
  • 原文地址:https://www.cnblogs.com/nb-blog/p/10647554.html
Copyright © 2020-2023  润新知