首先要安装docker这个环境是需要自己安装的。相关步骤如下:

1
2
3
4
5
6
7
8
9
10
11
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
安装docker
yum list docker-ce --showduplicates | sort -r 查看docker相关版本
#yum install docker-ce #由于repo中默认只开启stable仓库,故这里安装的是最新稳定版。
#yum install <FQPN> # 例如:yum install docker-ce-18.06.0.ce -y
#以下是验证过的版本,建议安装
yum install docker-ce-18.06.0.ce -y
systemctl start docker
systemctl enable docker
docker version(因为安装的是1.13.4版本的k8s,建议安装docker18.06)

然后使用阿里云修改好的minikube进行安装,否则在初始化minikube的时候会卡在墙上下不来

1
2
3
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.35.0/minikube-linux-amd64
chmod +x minikube
mv minikube /usr/bin/minikube
注意一点要关掉swap:关闭命令swapoff -a

加载阿里云k8s的官方源并且安装相关命令组件

1
2
3
4
5
6
7
8
9
10
cd /etc/yum.repos.d/
cat>>kubernetes.repo<<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
1
2
yum install kubectl kubelet kubeadm -y
systemctl start kubelet && systemctl enable kubelet

使用缺省VirtualBox驱动来创建Kubernetes本地环境

minikube start --registry-mirror=https://registry.docker-cn.com

出现如下字样

- Verifying component health .....
+ kubectl is now configured to use "minikube"
= Done! Thank you for using minikube!

则本地的minikube安装完成。当然这个不能访问外网,单独装ingress或者端口转发即可

############################################################################

----------------------------------我是分割线------------------------------------割一下--------------------------------

############################################################################

ingress安装方法:

生成ingress:

创建depolyment.yaml:

apiVersion: v1
kind: Namespace
metadata:
  name: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-configuration
  namespace: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: tcp-services
  namespace: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
kind: ConfigMap
apiVersion: v1
metadata:
  name: udp-services
  namespace: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: nginx-ingress-serviceaccount
  namespace: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
  name: nginx-ingress-clusterrole
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
rules:
  - apiGroups:
      - ""
    resources:
      - configmaps
      - endpoints
      - nodes
      - pods
      - secrets
    verbs:
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - nodes
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - services
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - "extensions"
    resources:
      - ingresses
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      - create
      - patch
  - apiGroups:
      - "extensions"
    resources:
      - ingresses/status
    verbs:
      - update
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: Role
metadata:
  name: nginx-ingress-role
  namespace: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
rules:
  - apiGroups:
      - ""
    resources:
      - configmaps
      - pods
      - secrets
      - namespaces
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      - configmaps
    resourceNames:
      # Defaults to "<election-id>-<ingress-class>"
      # Here: "<ingress-controller-leader>-<nginx>"
      # This has to be adapted if you change either parameter
      # when launching the nginx-ingress-controller.
      - "ingress-controller-leader-nginx"
    verbs:
      - get
      - update
  - apiGroups:
      - ""
    resources:
      - configmaps
    verbs:
      - create
  - apiGroups:
      - ""
    resources:
      - endpoints
    verbs:
      - get
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: nginx-ingress-role-nisa-binding
  namespace: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: nginx-ingress-role
subjects:
  - kind: ServiceAccount
    name: nginx-ingress-serviceaccount
    namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
  name: nginx-ingress-clusterrole-nisa-binding
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: nginx-ingress-clusterrole
subjects:
  - kind: ServiceAccount
    name: nginx-ingress-serviceaccount
    namespace: kube-system
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-ingress-controller
  namespace: kube-system
  labels:
    app.kubernetes.io/name: ingress-nginx
    app.kubernetes.io/part-of: ingress-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: ingress-nginx
      app.kubernetes.io/part-of: ingress-nginx
  template:
    metadata:
      labels:
        app.kubernetes.io/name: ingress-nginx
        app.kubernetes.io/part-of: ingress-nginx
      annotations:
        prometheus.io/port: "10254"
        prometheus.io/scrape: "true"
    spec:
      serviceAccountName: nginx-ingress-serviceaccount
      containers:
        - name: nginx-ingress-controller
          image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.23.0
          args:
            - /nginx-ingress-controller
            - --configmap=$(POD_NAMESPACE)/nginx-configuration
            - --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
            - --udp-services-configmap=$(POD_NAMESPACE)/udp-services
            - --publish-service=$(POD_NAMESPACE)/ingress-nginx
            - --annotations-prefix=nginx.ingress.kubernetes.io
          securityContext:
            allowPrivilegeEscalation: true
            capabilities:
              drop:
                - ALL
              add:
                - NET_BIND_SERVICE
            # www-data -> 33
            runAsUser: 33
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - name: http
              containerPort: 80
            - name: https
              containerPort: 443
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            initialDelaySeconds: 10
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /healthz
              port: 10254
              scheme: HTTP
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 10
---

---

---

再创建svc,yaml:

Service:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
apiVersion: v1
kind: Service
metadata:
  annotations:
    #service.beta.kubernetes.io/alicloud-loadbalancer-id: "lb-wz9du18pa4e7f93vetzww"
  labels:
    app: nginx-ingress
  name: nginx-ingress
  namespace: kube-system
spec:
  ports:
  - name: http
    nodePort: 30468
    port: 80
    protocol: TCP
    targetPort: 80
  - name: https
    nodePort: 30471
    port: 443
    protocol: TCP
    targetPort: 443
  selector:
    #app: ingress-nginx
    app.kubernetes.io/name: ingress-nginx
  #type: LoadBalancer
  type: NodePort
status:
  loadBalancer:
    ingress:
    - ip: 39.108.26.119(此处更改成自己本机ip)

以上yaml创建pod的命令是:

kubectl apply -f xxxx.yaml

业务镜像可以拉取gitlab的,这里没做cofigmap,需要自己配。生成业务编排需自己编写yaml

以下是简单安装脚本。

#!/bin/bash
#安装docker相关,用以拉取本地所需镜像,版本采用docker-ce .06版,支持1.13版kubernetes
#检测网卡是否是固定ip
grep -rE "dhcp" /etc/sysconfig/network-scripts/ifcfg-*
if [ $? -eq ];
then
echo "网卡为DHCP模式请更改为规定ip"
exit
else
echo "网卡正常。"
fi
yum clean all && yum repolist
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install docker-ce-18.06..ce -y
systemctl start docker
systemctl enable docker
VERSION=`docker version`
if [ $? -eq ];
then
echo "输出docker版本信息:$VERSION"
else
echo "docker安装出错,请检查错误日志"
exit
fi
echo "" >/proc/sys/net/bridge/bridge-nf-call-iptables #此步是保证iptables正确转发获取镜像,否则会报dns解析错误
########获取minikube二进制文件并且添加系统命令########
cd /data
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.35.0/minikube-linux-amd64
chmod +x minikube
mv minikube /usr/bin/minikube
swapoff -a #强制关闭swap不然初始化的时候会提示错误
cd /etc/yum.repos.d/
cat>>kubernetes.repo<<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=
gpgcheck=
repo_gpgcheck=
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
yum install kubectl kubelet kubeadm -y
systemctl start kubelet && systemctl enable kubelet
########启动minikube########
minikube start --vm-driver=none
if [ $? -eq ];
then
echo "minikube初始化成功"
else
echo "minikube初始化失败,请检查报错输出,重新执行初始化命令minikube start --vm-driver=none 命令,如果仍有报错,请执行清理集群命令minikube delete,并重新执行初始化命令!"
minikube delete
exit
fi
#缺省Minikube使用VirtualBox驱动来创建Kubernetes本地环境
#minikube start --registry-mirror=https://registry.docker-cn.com
STATUS=`kubectl get node | awk '{print$2}' | sed -n '2p'`
if [ $STATUS = "Ready" ];
then
echo "输出集群状态$STATUS"
else
echo "输出状态不是Ready,请联系运维."
fi
#echo "输出集群状态$STATUS"
#echo "输出状态不是Ready,请联系运维."

本地k8s环境minikube搭建过程的更多相关文章

  1. Ubuntu12.04嵌入式交叉编译环境arm-linu-gcc搭建过程,图解

    转载:王文松的博客Ubuntu12.04嵌入式交叉编译环境arm-linu-gcc搭建过程,图解 安装环境       Linux版本:Ubuntu 12.04    内核版本:Linux 3.5.0 ...

  2. Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程

    Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程Linux版本:Ubuntu 12.04 内核版本:Linux 3.5.0 交叉编译器版本:arm-linux-gcc-4. ...

  3. Ubuntu 上 hi3531 交叉编译环境 arm-hisiv100nptl-linux 搭建过程

    安装SDK 1.Hi3531 SDK包位置     在"Hi3531_V100R001***/01.software/board"目录下,您可以看到一个 Hi3531_SDK_Vx ...

  4. 3 微信开发本地代理环境的搭建--实现将内网ip映射到外网

    微信公众号的开发,要搭建网站,并且随时都有可能修改网站内容进行调试,这就需要临时外网能返回本地开发环境搭建的项目进行测试,即内网映射到公网,但是好多开发者没有自己的域名和服务器,这里我们先来搭建一个本 ...

  5. 本地+分布式Hadoop完整搭建过程

    1 概述 Hadoop在大数据技术体系中极为重要,被誉为是改变世界的7个Java项目之一(剩下6个是Junit.Eclipse.Spring.Solr.HudsonAndJenkins.Android ...

  6. 入门Kubernetes-minikube本地k8s环境

    前言: 在上一篇 结尾中使用到了minikube方式来做k8s本地环境来学习k8s. 那么这篇先了解下minikube及使用 一.Minikube 简介 minikube 在 macOS.Linux ...

  7. Kubernetes入门,使用minikube 搭建本地k8s 环境

    这是一篇 K8S 的 HelloWorld,在学习K8S官方文档时搭建环境搭建的一个记录,照着文档下来还是比较顺利的. 一.安装kubectl 下载 kubectl curl -LO "ht ...

  8. [kubernetes] 使用 Minikube 快速搭建本地 k8s 环境 (基于 Docker 驱动模式)

    一.实验环境 操作系统:Centos 7 x86_64 Docker:1.12.6 二.部署 k8s 步骤 2.1  安装 kubectl cat <<EOF > /etc/yum. ...

  9. K8S 使用Minikube搭建Kubernetes(K8S)~单机运行Kubernetes~适用于快速学习

    在一台主机上运行起来的Kubernetes,仅适用于学习!~~~ 系统版本:CentOS Linux release 7.6.1810 (Core) 软件版本:Docker-ce-18.06.0.Ku ...

随机推荐

  1. JavaSE基础知识(4)—数组的应用

    一.数组的特点.好处及使用步骤 1.数组的好处 特点:相当于用于保存一组元素的容器好处: 1.提高代码的简洁性和扩展性,且同时开辟多个空间,提高了效率 2.分类存储,且空间是连续的,容易查找 2.数组 ...

  2. PHP开发——环境安装

    PHP环境 Apache IDE的选择

  3. CentOS上部署.net core

    1.阿里云更换系统安装CentOS7.4 64位版本 2.试用XShell 5 登录服务器 参考https://www.microsoft.com/net/learn/get-started/linu ...

  4. python 用文本来提供输入信息的模板,不用每次都手动粘贴了

    #下面这一段用一个txt来保存input的信息来模拟input.最后提交代码时候删除这一段即可. a9999=open('1.txt','r') def input(): return a9999.r ...

  5. DB2 键约束操作

    DB2 键约束操作 今天遇到一个问题,想要删掉一个表中的某列的唯一约束,google了一下,搜出来许许多多,找到能用的,记下来总结如下. 命令如下 select constname, tabname, ...

  6. 腾讯云的基本配置(centos 7.1)及mysql的使用

    因为想在微信上开发些东西,所以租用了一个月的腾讯云. 推荐选择的镜像是centos7.1.这个系统的选择和本地操作系统基本没有关系. 首先要登录到云主机中,用户名是root,密码是当初自己设置的那一个 ...

  7. spring web参数传递

    spring boot 参数相关 ******************************************   @RequestParam 这个注解用来绑定单个请求数据,既可以是url中的 ...

  8. 20175316盛茂淞 2018-2019-2 《Java程序设计》第2周课上测试总结

    20175316 2018-2019-2 <Java程序设计>第2周课上测试总结 上周考试题目总结 题目1 题目要求: 在Ubuntu中用自己的有位学号建一个文件,教材p29 Exampl ...

  9. ABP框架系列之四十一:(Nuget-Packages-Nuget包)

    Packages ASP.NET Boilerplate is distributed on nuget. Here, a list of all official packages. Abp Cor ...

  10. Python语言中的按位运算

    (转)位操作是程序设计中对位模式或二进制数的一元和二元操作. 在许多古老的微处理器上, 位运算比加减运算略快, 通常位运算比乘除法运算要快很多. 在现代架构中, 情况并非如此:位运算的运算速度通常与加 ...