首页 > 其他分享 >k8s-安装教程

k8s-安装教程

时间:2022-09-20 16:13:18浏览次数:79  
标签:教程 kube name kubernetes k8s 安装 cni flannel

kubelet版本过高,v1.24版本后kubernetes放弃docker了,所以我们安装1.24以下的。

以下操作三台主机都要做。

#关闭防火墙
systemctl stop firewalld && systemctl disable firewalld

#安装docker
curl -sSL https://get.daocloud.io/docker | sh


#修改docker仓库在 /etc/docker 创建 daemon.json
{
    "registry-mirrors": ["https://3yhtn13w.mirror.aliyuncs.com"],
    "exec-opts": ["native.cgroupdriver=systemd"]
}

#启动docker
systemctl enable docker && systemctl start docker

#修改主机名
hostnamectl set-hostname k8s-master1
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2

#设置主机映射 vim /etc/hosts
192.168.180.137 k8s-master1
192.168.180.133 k8s-node1
192.168.180.134 k8s-node2

#Linux系统禁用swap分区
swapoff -a

vi /etc/fstab
#/dev/mapper/centos-swap swap                    swap    defaults        0 0

#将 SELinux 设置为 permissive 模式(相当于将其禁用)
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

#拉去k8s配置文件
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
exclude=kubelet kubeadm kubectl
EOF

#安装kubelet kubeadm kubectl
yum list --showduplicates kubeadm --disableexcludes=kubernetes #查询版本
yum install -y kubelet-1.23.11-0 kubeadm-1.23.11-0 kubectl-1.23.11-0 --disableexcludes=kubernetes #安装

#启动kubelet
systemctl enable kubelet && systemctl start kubelet

以下操作仅master做

#拉资源文件
kubeadm config print init-defaults > kubeadm-init.yaml

#修改文件
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers #镜像源
advertiseAddress: 192.168.180.137 #本机ip
name: k8s-master #主机名
kubernetesVersion: 1.25.1 #k8s版本号
serviceSubnet: 10.96.0.0/12
podSubnet: 10.244.0.0/16

#初始化kubeadm
kubeadm config images pull --config kubeadm-init.yaml  #拉取镜像
kubeadm init  --config=kubeadm-init.yaml #初始化

安装成功提示以下内容

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:
  #执行下边三行
  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config #执行
  sudo chown $(id -u):$(id -g) $HOME/.kube/config #执行

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

#node加入使用以下命令
kubeadm join 192.168.180.137:6443 --token abcdef.0123456789abcdef \
    --discovery-token-ca-cert-hash sha256:b73f9d773c7b7dfd29a2ad019b770a2212ea1a21abc6a9cfb7d03addd3bc48f3

Node执行上边的加入命令

master安装网络插件

vim kube-flannel.yaml 下载不下来,所以把我的复制过去就行。

---
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
  name: psp.flannel.unprivileged
  annotations:
    seccomp.security.alpha.kubernetes.io/allowedProfileNames: docker/default
    seccomp.security.alpha.kubernetes.io/defaultProfileName: docker/default
    apparmor.security.beta.kubernetes.io/allowedProfileNames: runtime/default
    apparmor.security.beta.kubernetes.io/defaultProfileName: runtime/default
spec:
  privileged: false
  volumes:
  - configMap
  - secret
  - emptyDir
  - hostPath
  allowedHostPaths:
  - pathPrefix: "/etc/cni/net.d"
  - pathPrefix: "/etc/kube-flannel"
  - pathPrefix: "/run/flannel"
  readOnlyRootFilesystem: false
  runAsUser:
    rule: RunAsAny
  supplementalGroups:
    rule: RunAsAny
  fsGroup:
    rule: RunAsAny
  allowPrivilegeEscalation: false
  defaultAllowPrivilegeEscalation: false
  allowedCapabilities: ['NET_ADMIN', 'NET_RAW']
  defaultAddCapabilities: []
  requiredDropCapabilities: []
  hostPID: false
  hostIPC: false
  hostNetwork: true
  hostPorts:
  - min: 0
    max: 65535
  seLinux:
    rule: 'RunAsAny'
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: flannel
rules:
- apiGroups: ['extensions']
  resources: ['podsecuritypolicies']
  verbs: ['use']
  resourceNames: ['psp.flannel.unprivileged']
- apiGroups:
  - ""
  resources:
  - pods
  verbs:
  - get
- apiGroups:
  - ""
  resources:
  - nodes
  verbs:
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - nodes/status
  verbs:
  - patch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: flannel
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: flannel
subjects:
- kind: ServiceAccount
  name: flannel
  namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: flannel
  namespace: kube-system
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: kube-flannel-cfg
  namespace: kube-system
  labels:
    tier: node
    app: flannel
data:
  cni-conf.json: |
    {
      "name": "cbr0",
      "cniVersion": "0.3.1",
      "plugins": [
        {
          "type": "flannel",
          "delegate": {
            "hairpinMode": true,
            "isDefaultGateway": true
          }
        },
        {
          "type": "portmap",
          "capabilities": {
            "portMappings": true
          }
        }
      ]
    }
  net-conf.json: |
    {
      "Network": "10.244.0.0/16",
      "Backend": {
        "Type": "vxlan"
      }
    }
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: kube-flannel-ds
  namespace: kube-system
  labels:
    tier: node
    app: flannel
spec:
  selector:
    matchLabels:
      app: flannel
  template:
    metadata:
      labels:
        tier: node
        app: flannel
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/os
                operator: In
                values:
                - linux
      hostNetwork: true
      priorityClassName: system-node-critical
      tolerations:
      - operator: Exists
        effect: NoSchedule
      serviceAccountName: flannel
      initContainers:
      - name: install-cni-plugin
        image: rancher/mirrored-flannelcni-flannel-cni-plugin:v1.1.0
        command:
        - cp
        args:
        - -f
        - /flannel
        - /opt/cni/bin/flannel
        volumeMounts:
        - name: cni-plugin
          mountPath: /opt/cni/bin
      - name: install-cni
        image: rancher/mirrored-flannelcni-flannel:v0.18.1
        command:
        - cp
        args:
        - -f
        - /etc/kube-flannel/cni-conf.json
        - /etc/cni/net.d/10-flannel.conflist
        volumeMounts:
        - name: cni
          mountPath: /etc/cni/net.d
        - name: flannel-cfg
          mountPath: /etc/kube-flannel/
      containers:
      - name: kube-flannel
        image: rancher/mirrored-flannelcni-flannel:v0.18.1
        command:
        - /opt/bin/flanneld
        args:
        - --ip-masq
        - --kube-subnet-mgr
        resources:
          requests:
            cpu: "100m"
            memory: "50Mi"
          limits:
            cpu: "100m"
            memory: "50Mi"
        securityContext:
          privileged: false
          capabilities:
            add: ["NET_ADMIN", "NET_RAW"]
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: EVENT_QUEUE_DEPTH
          value: "5000"
        volumeMounts:
        - name: run
          mountPath: /run/flannel
        - name: flannel-cfg
          mountPath: /etc/kube-flannel/
        - name: xtables-lock
          mountPath: /run/xtables.lock
      volumes:
      - name: run
        hostPath:
          path: /run/flannel
      - name: cni-plugin
        hostPath:
          path: /opt/cni/bin
      - name: cni
        hostPath:
          path: /etc/cni/net.d
      - name: flannel-cfg
        configMap:
          name: kube-flannel-cfg
      - name: xtables-lock
        hostPath:
          path: /run/xtables.lock
          type: FileOrCreate
View Code

kubectl create -f kube-flannel.yaml

完毕!

标签:教程,kube,name,kubernetes,k8s,安装,cni,flannel
From: https://www.cnblogs.com/zumengjie/p/16711384.html

相关文章

  • 计算机安装不同版本sqlserver如何使用
    1.两个版本需要使用不同的实例名称2.设置不同的端口号3.客户端连接方式:ip地址,端口号4.如果需要远程连接,启用出入站的端口号新建入站规则:1出站规则和入站规......
  • PS新手教程-如何使用ps给人像皮肤去除斑点
    如何使用ps给人像皮肤去除斑点?给大家介绍如何使用ps给人像皮肤去除斑点,一起来看看吧。人像皮肤去除斑效果图如下1、打开ps,人像照片导入。2、复制一个图层。3、按键......
  • Windows安装Jenkins详细教程(图文教程)
    一、安装前准备1、提前安装好jdk,可参考以下链接进行安装Windows安装JDK详细教程(图文教程)2、Jenkins官网下载安装包(因为本人jdk安装的是1.8,所以会和最新版jenkins不符合,......
  • containerd安装
    下载安装包wgethttps://github.com/containerd/containerd/releases/download/v1.6.8/cri-containerd-1.6.8-linux-amd64.tar.gzwgethttps://github.com/opencontainer......
  • paddleocr安装与图片识别快速开始
    本文首发我的个人博客:paddleocr安装教程快速开始1.安装Python环境wgethttps://mirrors.huaweicloud.com/python/3.8.5/Python-3.8.5.tgz下载后,解压,编译,安装,即可。......
  • docker离线安装
    //下载静态包//https://download.docker.com/linux/static/stable///解压tgz包到docker文件夹tar-xzvfdocker.tgz//将docker文件复制到/usr/bin下sudocpdocker/*/us......
  • Docker安装部署Mysql8(以作数据持久化)
    1.创建容器并进行持久化处理#拉取镜像dockerpullmysql:8.0.20#启动镜像,用于拷贝配置文件到宿主机dockerrun-p3306:3306--namemysql-eMYSQL_ROOT_PASSWORD=12......
  • 安装配置docker&maven环境
     原文视频:(https://blog.sechelper.com/20220919/code-review/docker-maven-install-guid/)Docker是什么Docker是一个开源的应用容器引擎。Docker可以让开发者打包他们......
  • k8s中配置存储ConfigMap和Secret
    ConfigMapConfigMap是一种比较特殊的存储卷,它的主要作用是用来存储配置信息的。Secret在kubernetes中,还存在一种和ConfigMap非常类似的对象,称为Secret对象。它主要用......
  • ES介绍-安装-插件-ElasticSearch-head-ElasticSearch-安装Kibana
    ES介绍 #大规模数据如何存储和检索---》elasticsearch#Elasticsearch是一个基于Lucene的分布式搜索和分析引擎,分布式全文检索引擎,java开发,遵循apache开源协议使......