SealOS 一键安装 K8S

环境

# 查看系统发行版
$ cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

# 查看本机 IP(192.168.213.37)
$ ip addr
...
enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:12:05:d6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.213.37/24 brd 192.168.213.255 scope global noprefixroute dynamic enp0s8
       valid_lft 534sec preferred_lft 534sec
    inet6 fe80::95b2:c44f:3065:e6e/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
...

添加源

# 添加源
$ cat > /etc/yum.repos.d/labring.repo << EOF
[fury]
name=labring Yum Repo
baseurl=https://yum.fury.io/labring/
enabled=1
gpgcheck=0
EOF

# 清理缓存
$ yum clean all

安装 SealOS

# 安装 SealOS
$ yum install sealos
# 查看版本
$ sealos version
CriVersionInfo:
  RuntimeApiVersion: v1
  RuntimeName: containerd
  RuntimeVersion: v1.6.17
  Version: 0.1.0
KubernetesVersionInfo:
  clientVersion:
    buildDate: "2022-08-23T17:44:59Z"
    compiler: gc
    gitCommit: a866cbe2e5bbaa01cfd5e969aa3e033f3282a8a2
    gitTreeState: clean
    gitVersion: v1.25.0
    goVersion: go1.19
    major: "1"
    minor: "25"
    platform: linux/amd64
  kustomizeVersion: v4.5.7
  serverVersion:
    buildDate: "2022-08-23T17:38:15Z"
    compiler: gc
    gitCommit: a866cbe2e5bbaa01cfd5e969aa3e033f3282a8a2
    gitTreeState: clean
    gitVersion: v1.25.0
    goVersion: go1.19
    major: "1"
    minor: "25"
    platform: linux/amd64
SealosVersion:
  buildDate: "2023-02-20T02:50:39Z"
  compiler: gc
  gitCommit: 1d7649e4
  gitVersion: 4.1.5-rc2
  goVersion: go1.20.1
  platform: linux/amd64

安装 K8S

# 单机部署
sealos run labring/kubernetes:v1.25.0 labring/helm:v3.8.2 labring/calico:v3.24.1 --single
# 设置 master 节点可以部署 pod
kubectl taint nodes --all node-role.kubernetes.io/master-
kubectl taint nodes --all node-role.kubernetes.io/control-plane-

安装 K8S Dashboard

Dashboard 版本需要与 K8S 版本相匹配,参考:https://github.com/kubernetes/dashboard/releases

# 下载镜像
$ sealos pull kubernetesui/dashboard:v2.7.0
$ sealos images
REPOSITORY                         TAG       IMAGE ID       CREATED        SIZE
docker.io/labring/kubernetes       v1.25.0   06f5d19b019c   8 days ago     528 MB
docker.io/library/nginx            latest    3f8a00f137a0   13 days ago    146 MB
docker.io/kubernetesui/dashboard   v2.7.0    07655ddf2eeb   5 months ago   249 MB
docker.io/labring/calico           v3.24.1   e2122fc58fd3   5 months ago   354 MB
docker.io/labring/helm             v3.8.2    1123e8b4b455   6 months ago   45.1 MB

# 下载 deployment yaml 
>$ wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml
# 更改为 NodePort 访问
$ vim recommended.yaml

SealOS 一键安装 K8S_第1张图片

# 部署 dashboard
$ kubectl apply -f recommended.yaml

# 查看 dashboard NodePort 端口(32688)
$ kubectl get svc -n kubernetes-dashboard
NAME                        TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)         AGE
dashboard-metrics-scraper   ClusterIP   10.96.3.61   <none>        8000/TCP        11m
kubernetes-dashboard        NodePort    10.96.1.40   <none>        443:32688/TCP   11m

# 创建访问账号
$ kubectl create namespace xchenhao
$ kubect create serviceaccount xchenhao-admin -n xchenhao
$ cat > admin-user.yaml << EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: xchenhao-admin
  namespace: xchenhao
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: xchenhao-admin
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: xchenhao-admin
  namespace: xchenhao
EOF

$ kubectl apply -f admin-user.yaml

# 生成 Token
$ kubectl create token xchenhao-admin --duration 24h -n xchenhao
eyJhbGciOiJSUzI1NiIsImtpZCI6InlGdU5hN3hpcU9jcWM4Zm1T.....aSWNyVrBnRxjHA

浏览器访问 Dashboard

访问 机器 IP:NodePort 端口

SealOS 一键安装 K8S_第2张图片

部署一个服务(Nginx)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      name: test-nginx
  template:
    metadata:
      labels:
        name: test-nginx
    spec:
      containers:
        - name: test-nginx
          image: hub.c.163.com/library/nginx
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: test-nginx-service-nodeport
spec:
  ports:
    - port: 80
      targetPort: 80
      protocol: TCP
  type: NodePort
  selector:
    name: test-nginx

SealOS 一键安装 K8S_第3张图片
Nginx NodePort 为 32272
SealOS 一键安装 K8S_第4张图片
浏览器访问 192.168.213.37:32272
SealOS 一键安装 K8S_第5张图片

参考

  • https://github.com/labring/sealos
  • https://www.qycn.com/xzx/article/14034.html 如何查看 linux 发行版本系统,有哪些方法
  • https://blog.csdn.net/xmcy001122/article/details/127223735 k8s dashboard 安装
  • https://www.cnblogs.com/zhanchenjin/archive/2022/07/15/16481954.html kubernetes1.24+containerd 搭建
  • https://itnext.io/big-change-in-k8s-1-24-about-serviceaccounts-and-their-secrets-4b909a4af4e0 BIG change in K8s 1.24 about ServiceAccounts and their Secrets
  • https://blog.csdn.net/xchenhao/article/details/103183823 CentOS7 部署 Kubernetes 流程

你可能感兴趣的:(运维,docker,kubernetes,linux,运维)