k8s 概念梳理 搭建集群 基本操作

k8s 核心概念思维导图

集群搭建

  • 单节点
https://my.oschina.net/u/731542/blog/2966427 (单机版)
补充:
1 init之前设置hosts 关闭swap
disable swap swapoff -a && sysctl -p
kubeadm init  --kubernetes-version=1.12.3 --pod-network-cidr=10.244.0.0/16

2 报错: [ERROR KubeletVersion]: the kubelet version is higher than the control plane version.
yum -y remove kubelet
yum -y install kubelet-1.12.3 kubeadm-1.12.3
  • 多节点
https://www.kubernetes.org.cn/4387.html

init_mini_k8s.sh

#!/bin/bash

## 准备工作
# 修改主机名 请手动重启一下
# hostnamectl set-hostname  k8s-master
# disable swap
# swapoff -a && sysctl -p
# 重启系统
# reboot

## 安装docker
yum -y install policycoreutils-python*
wget http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.68-1.el7.noarch.rpm
rpm -ivh container-selinux-2.68-1.el7.noarch.rpm
yum install -y libltdl.so*
yum install -y pigz*
wget https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/Packages/docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm
rpm -ivh docker-ce-18.03.1.ce-1.el7.centos.x86_64.rpm

## 切换 k8s yum 源
touch /etc/yum.repos.d/kubernetes.repo
cat >> /etc/yum.repos.d/kubernetes.repo <

入门操作

  • 创建查看集群

    kubectl get nodes -o wide  # 查看集群节点信息
    kubectl cluster-info  # Display cluster info 显示集群信息
  • 部署应用

    kubectl run my-ngx --image=nginx:latest --port=80  # 部署应用
    
    old: kubectl run -i --tty load-generator --image=busybox /bin/sh
    new: kubectl run --generator=run-pod/v1 -i --tty load-generator --image=busybox /bin/sh
  • 发布应用

    kubectl expose deployment my-ngx --type='NodePort' --port=80  # 发布应用
    kubectl get services/my-ngx    # 查看my-ngx服务
    kubectl describe services/my-ngx  # 查看详细信息
    curl 10.9.2.42:19999    #  curl NodeIP:NodePort
  • 扩容缩容

    kubectl scale deployment/my-ngx --replicas=2  # 扩容
    kubectl get pods -o wide
    kubectl scale deployment/my-ngx --replicas=1  # 缩容
  • 更新回滚

    kubectl set image deployment/my-ngx my-ngx=nginx:1.9  # 滚动更新
    kubectl rollout undo deployment/my-ngx   # 回滚
  • 删除

    kubectl get pods      # 查看pods
    kubectl get deployment  # 查看deployment服务
    kubectl delete pods my-ngx-59497d7745-qzwqz  # 删除pods
    kubectl delete deployment my-ngx  # 删除deployment
  • 查看错误信息

    journalctl -f -u kubelet

参考

<>
https://www.kubernetes.org.cn/4387.html  # 安装集群

你可能感兴趣的:(golang,docker,k8s)