• kubernetes学习第一篇-k8s安装以及HelloWorld


    安装

    1. 关闭防火墙服务

    # systemctl disable firewalld
    # systemctl stop firewalld  

    2. 安装etcd以及kubernetes软件

    yum install -y etcd kubernetes

    3. 修改Docker配置为

    vim /etc/sysconfig/docker
    OPTIONS='--selinux-enabled=false --insecure-registry grc.io --log-driver=journald --signature-verification=false'
    

    4.按顺序启动服务

    systemctl start etcd
    systemctl start docker
    systemctl start kube-apiserver
    systemctl start kube-controller-manager
    systemctl start kube-scheduler
    systemctl start kubelet
    systemctl start kubelet
    systemctl start kube-proxy
    

    5. 检查是否启动成功

    HelloWorld

    1. 编写一个配置文件mysql-rc.yaml

    apiVersion: v1
    #副本控制器
    kind: ReplicationController
    metadata:
      name: mysql
    spec:
      # 实例的数量
      replicas: 1
      selector:
        # Pod名称
        app: mysql
      template:
        metadata:
          # Pod副本名称对应selector
          labels:
            app: mysql
        spec:
          containers:    # Pod内容定义部分
          - name: mysql  # 容器的名称
            image: mysql # 容器的镜像
            ports:
            - containerPort: 3306 ## 暴露端口
            env: ##注入到容器内的环境变量
            - name: MYSQL_ROOT_PASSWORD
              value: "123456"
    

    2. 启动

    kubectl create -f mysql-rc.yaml
    

    3. 查看状态

    # kubectl get rc
    NAME      DESIRED   CURRENT   READY     AGE
    mysql     1         1         1         14m
    

    Pod状态

    # kubectl get pods
    NAME          READY     STATUS    RESTARTS   AGE
    mysql-w3t8z   1/1       Running   0          14m
    

    4. 问题解决

    1. 启动后发现 Pod状态一直都是ContainerCreating

      1. 使用kubectl describe po mysql查看状态

      2. 如果出现如下错误

    kubectl describe po  mysql-bwnlk
    Name:       mysql-bwnlk
    Namespace:  default
    Node:       127.0.0.1/127.0.0.1
    Start Time: Thu, 04 Jan 2018 10:20:45 +0800
    Labels:     app=mysql
    Status:     Pending
    IP:     
    Controllers:    ReplicationController/mysql
    Containers:
      mysql:
        Container ID:   
        Image:      daocloud.io/library/mysql
        Image ID:       
        Port:       3306/TCP
        State:      Waiting
          Reason:       ContainerCreating
        Ready:      False
        Restart Count:  0
        Volume Mounts:  <none>
        Environment Variables:
          MYSQL_ROOT_PASSWORD:  123456
    Conditions:
      Type      Status
      Initialized   True 
      Ready     False 
      PodScheduled  True 
    No volumes.
    QoS Class:  BestEffort
    Tolerations:    <none>
    Events:
      FirstSeen LastSeen    Count   From            SubObjectPath   Type        Reason      Message
      --------- --------    -----   ----            -------------   --------    ------      -------
      3m        3m      1   {default-scheduler }        Normal      Scheduled   Successfully assigned mysql-bwnlk to 127.0.0.1
      3m        20s     5   {kubelet 127.0.0.1}     Warning     FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.  details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"
    
      2m    8s  10  {kubelet 127.0.0.1}     Warning FailedSync  Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image "registry.access.redhat.com/rhel7/pod-infrastructure:latest""
    

      解决:

    yum install *rhsm*
    

      安装服务

    #wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
    #rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
    

      删除原先的服务

    kubectl delete -f mysql-rc.yaml
    kubectl create -f mysql-rc.yaml
    

      

    问题2:docker下载pull失败问题

    1. 安装阿里镜像加速即可解决https://cr.console.aliyun.com/cn-hangzhou/mirrors

  • 相关阅读:
    解决在Pycharm中无法显示代码提示的问题
    解决在使用pip list时出现DEPRECATION
    Pycharm 有些库(函数)没有代码提示
    Oracle 11.2.0.4 For Windows 64bit+32bit 数据库
    Windows系统下oracle数据库每天定时备份
    PowerDesigner表创建脚本双引号问题
    Oracle11g 创建数据库中问题处理(必须运行Netca以配置监听程序)
    名人名言
    项目管理
    项目管理心得:一个项目经理的个人体会、经验总结(zz)
  • 原文地址:https://www.cnblogs.com/lonecloud/p/10390788.html
Copyright © 2020-2023  润新知