• CentOS下的安装测试K8S(守护进程式)


    master: 192.168.0.100

    node1: 192.168.0.105
    node2: 192.168.0.106

     一,k8s基本操作命令:

    k8s全名:kubernetes,
    容器编排工具,说白了就是自动化管理容器的工具。包括:

    • 服务自动注册和发现
    • 负载均衡
    • 健康监测
    • 自动申缩
    • 冗余容灾

    基本操作命令:

    创建:kubectl create -f xxx.yaml
         kubectl apply -f xxx.yaml
    查询:
    kubectl get pod yourPodName
    
    kubectl describe pod yourPodName //这个我一般用来排查机器无故没有Running
    
    删除:kubectl delete pod yourPodName
    强制删除: kubectl delete pod PODNAME --force --grace-period=0
    
    更新:kubectl replace /path/to/yourNewYaml.yaml

    二,k8s_master安装配置:

    2.1,关闭selinux,关闭防火墙,升级yum

    setenforce 0
    systemctl stop firewalld.service
    yum update

    2.2,安装并配置k8s

    yum -y install epel-release
    yum -y install etcd kubernetes-master

    #配置
    vi /etc/etcd/etcd.conf vi /etc/kubernetes/apiserver

    2.3,启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服务,并设置开机启动

    for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; 
    do systemctl restart $SERVICES;
    systemctl enable $SERVICES;
    systemctl status $SERVICES ;
    done

    2.4,定义flannel网络
    etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'


    三,k8s_node安装配置:

    3.1,关闭selinux,关闭防火墙,升级yum

    setenforce 0
    systemctl stop firewalld.service
    yum update

    3.2,安装docker,并配置阿里云加速

    yum install docker
    docker -v ##查看版本
    service docker start ##开启docker服务才能用其他命令
    chkconfig docker on
    docker images

    配置vim /etc/docker/daemon.json

    {
    "registry-mirrors": [ "https://cd6xo91e.mirror.aliyuncs.com"]
    }

    3.3,安装并配置k8s,,并启动

    yum -y install epel-release
    yum -y install flannel kubernetes-node
    
    #配置
    vi /etc/sysconfig/flanneld
    vi /etc/kubernetes/config
    vi /etc/kubernetes/kubelet

    3.4,node节点机上启动kube-proxy,kubelet,docker,flanneld等服务,并设置开机启动

    for SERVICES in kube-proxy kubelet docker flanneld;
    do systemctl restart $SERVICES;
    systemctl enable $SERVICES;
    systemctl status $SERVICES;
    done

    四,编排

    创建/root/k8s/tomcat01.yaml文件

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: myweb
    spec:
      replicas: 3
      template:
        metadata:
          name: test-namespace
          labels:
            app: myweb
        spec:
          containers:
          - name: myweb
            image: docker.io/nginx:1.18.0-alpine
            ports:
            - containerPort: 80
    
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: myweb
    spec:
       ports:
       - port: 80
         targetPort: 80
         nodePort: 31111
       selector:
         app: myweb
       type: NodePort

    nginx开放的80,如果是tomcat开放的8080,文件里面80都改成8080即可

    kubectl create -f tomcat01.yaml
    
    #如果配置错了,创建了一个错误的service和pod,可以用删除命令,配置正确后再重新创建一遍
    kubectl delete -f tomcat01.yaml

    检查一下pod和service:

    kubectl get pods -o wide
    
    kubectl get svc

    #如果两个pods的状态都是ContainerCreating,而不是running,说明kubectl create -f xxx操作是失败的,察看日志
    kubectl describe pods myweb-3889544643-3sxrb

    五、排障,测试

    5.1 错误:redhat-ca.crt
    解决方法:

    yum install *rhsm* -y

    5.2 错误:kubelet does not have ClusterDNS IP configured and cannot create Pod using "ClusterFirst" policy. Fail
    解决方法:

    master:
    通过环境变量,配置参数
    [root@k8s-master dns]# vi ~/.bash_profile #添加下面三行

    export DNS_SERVER_IP="10.254.10.2"
    export DNS_DOMAIN="cluster.local"
    export DNS_REPLICAS=1

    设置 Cluster DNS Service的IP为 10.254.10.2(不能和已分配的IP重复,如10.0.10.0),Cluster DNS的本地域为 cluster.local。

    node:
    在vi /etc/kubernetes/kubelet 配置文件中添加如下内容即可

    KUBE_ARGS="--cluster-dns=10.254.10.2 --cluster-domain=cluster.local"
    重启
    systemctl daemon
    -reload; systemctl restart kubelet
  • 相关阅读:
    RESTFUL API 安全设计指南
    智能设备逆向工程之外部Flash读取与分析篇
    物联网安全拔“牙”实战——低功耗蓝牙(BLE)初探
    linux&win7双系统安装
    智能设备只依托加速度感应计算距离是否可行?
    解决T400T500W500等安装win10驱动后黑屏问题
    TCP连接的状态与关闭方式及其对Server与Client的影响
    轻松解决Linux安装Eclipse方法
    京东实习面试
    北森云面试
  • 原文地址:https://www.cnblogs.com/lxsky/p/13925156.html
Copyright © 2020-2023  润新知