k8s的简单搭建

1、一般虚拟机为动态ip,而k8s搭建需要在配置文件中添加ip,如果ip动态变化,那配置文件中的ip也要相应变化。所以首先将虚拟机ip设置为静态ip。

  • ifconfig      :查看自己网卡名称,我的是ens33

k8s的简单搭建_第1张图片

  • vi /etc/sysconfig/network-scripts/ifcfg-ens33   :修改配置文件

            将BOOTPROTO改为static

           增加 IPADDR=192.168.250.101
                   GATEWAY=192.168.250.2
                   NM_CONTROLLED = no
                   DNS1 =192.168.250.2

  • systemctl restart network    :重新启动就ok了
  • 设置为静态ip后,不能ping域名,需设置   vi /etc/resolv.conf
    nameserver 114.114.114.114
    nameserver 8.8.8.8
    

     

2、配置master(192.168.250.101)

  • 安装etcd
  • 关闭防火墙 ,下载k8s

        systemctl disable firewalld

        systemctl stop firewalld
        yum install -y  kubernetes

  • 启动

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

  • vi /etc/kubernetes/apiserve  

       

k8s的简单搭建_第2张图片

 systemctl restart kube-apiserver:重新启动,所修改的便生效

  • vi /etc/kubernetes/controller-manager   

k8s的简单搭建_第3张图片

systemctl restart kube-controller-manager

  • vi /etc/kubernetes/scheduler    

k8s的简单搭建_第4张图片

systemctl restart kube-scheduler

  • kubectl get cs :检查是否安装正确

3、配置node(192.168.250.102)

node上docker与k8s的版本需对应

  • 下载k8s与上边的一样
  • 启动

    systemctl start docker

    systemctl start kube-proxy

    systemctl start kubelet

  • vi /etc/kubernetes/config    

k8s的简单搭建_第5张图片

systemctl restart kube-proxy

  • vi /etc/kubernetes/kubelet  

k8s的简单搭建_第6张图片

创建 vi /var/lib/kubelet/kubeconfig 向master注册

apiVersion: v1
kind: Config
users:
- name: kubelet
clusters:
- name: kubernetes
  cluster:
    server: http://192.168.250.101:8080
contexts:
- context:
    cluster: kubernetes
    user: kubelet
  name: service-account-context
current-context: service-account-context

systemctl restart kubelet

  • 在master      执行 kubectl get node 验证节点是否安装成功

    k8s的简单搭建_第7张图片

    并创建简单的nginx5.yaml文件

    apiVersion: v1
    kind: Pod
    metadata:
      name: nginx77
      labels:
        app: nginx
      namespace: default
    spec:
      containers:
      - image: hub.mfwdev.com/kubernetes/nginx
    
        imagePullPolicy: IfNotPresent
        name: nginx-deployment-6499c587d8
      restartPolicy: Always
    

     kubectl apply -f nginx5.yaml

  • kubectl get pods

    k8s的简单搭建_第8张图片

     

你可能感兴趣的:(k8s的简单搭建)