V记在4月推出Tanzu 1.3以后,原有的TKG命令堆栈完全废弃,改为Tanzu命令集。如初始化命令tkg init改为了tanzu management-cluster create,同时有些参数在这个版本的tanzu命令中并没有继承。
更多信息参考Tanzu CLI Command Reference
关于Tanzu 1.3.1的更新情况,参考VMware Tanzu Kubernetes Grid 1.3.1 Release Notes
本实验使用Tanzu cli命令在已经安装好的vSphere with Tanzu环境中创建Tanzu Kubernetes集群。
环境参数
项目 | 描述 | 备注 |
---|---|---|
vSphere | vSphere7.0u2a | 17867351 |
vCenter | VCSA-.7.0.2 | 17920168 |
NSX-T Datacenter | 3.1.2.1.0 | 17975796 |
Tanzu | 1.3.1 |
准备工作
部署vSphere with Tanzu工作负载平台
具体过程可以参考:安装VMware vSphere 7 with WCP平台,由于版本的变化,个别地方有所改变。
注意在现在的版本一开始就要建立一个内容库,并导入建立Cluster需要的虚机镜像。
虚机镜像下载地址:https://wp-content.vmware.com/v2/latest/,选择需要的版本。
建立Namespace并选择VM服务类和内容库
准备一台操作主机,并安装Tanzu CLI
操作主机要求
- 操作主机也称为引导计算机,可以是Linux,Windows或macOS操作系统
- 最低系统配置为6 GB的RAM和2核CPU
- 在引导计算机上安装并运行的Docker客户端
- 系统时间与网络时间协议(NTP)服务器同步
[root@localhost tanzu]# rpm -q ntp
ntp-4.2.6p5-29.el7.centos.x86_64
[root@localhost tanzu]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@localhost tanzu]# systemctl start ntpd
[root@localhost tanzu]# vim /etc/ntp.conf
[root@localhost tanzu]# systemctl restart ntpd
[root@localhost tanzu]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
router.corp.tan 10.16.188.210 4 u 13 64 1 2.659 9035.75 0.000
localhost .INIT. 16 l - 64 0 0.000 0.000 0.000
[root@localhost tanzu]# ntpstat
synchronised to NTP server (192.168.100.1) at stratum 5
time correct to within 138 ms
polling server every 64 s
我们使用CentOS 7 1906
安装Tanzu CLI
- 在V记官网下载 VMware Tanzu CLI 1.3.1 CLI.和Kubectl 1.20.5 for VMware Tanzu Kubernetes Grid 1.3.1并解压放入~/tanzu。
- 安装 binary 文件到 /usr/local/bin:
sudo install core/v1.3.1/tanzu-core-linux_amd64 /usr/local/bin/tanzu
- 安装Tanzu CLI Plugins
tanzu plugin install --local cli all
查看安装结果
[root@localhost Downloads]# tanzu plugin list
NAME LATEST VERSION DESCRIPTION REPOSITORY VERSION STATUS
alpha v1.3.1 Alpha CLI commands core not installed
cluster v1.3.1 Kubernetes cluster operations core v1.3.1 installed
kubernetes-release v1.3.1 Kubernetes release operations core v1.3.1 installed
login v1.3.1 Login to the platform core v1.3.1 installed
management-cluster v1.3.1 Kubernetes management cluster operations core v1.3.1 installed
pinniped-auth v1.3.1 Pinniped authentication operations (usually not directly invoked) core v1.3.1 installed
安装Kubectl
在解压出来的Kubectl文件拷贝到
cp kubectl /usr/local/bin/
kubectl version
Client Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.5+vmware.1"
实验步骤
将Supervisor Cluster加入管理集群
登录Superior Cluster
[root@localhost tanzu]# kubectl-vsphere login --server=https://172.80.88.1 --vsphere-username administrator@vsphere.local --insecure-skip-tls-verify
KUBECTL_VSPHERE_PASSWORD environment variable is not set. Please enter the password below
Password:
Logged in successfully.
You have access to the following contexts:
172.80.88.1
ns-dev
If the context you wish to use is not in this list, you may need to try
logging in again later, or contact your cluster administrator.
To change context, use `kubectl config use-context <workload name>`
[root@localhost Downloads]# kubectl config use-context 172.80.88.1
Switched to context "172.80.88.1".
使用 kubectl vsphere login加入管理集群
tanzu login --name my-super --kubeconfig ~/.kube/config --context 172.80.88.1
✔ successfully logged in to management cluster using the kubeconfig my-super
其中~/.kube/config是默认的KUBECONFIG文件
再次使用tanzu login命令可以看到有哪些管理集群并可以选择
[root@localhost Downloads]# tanzu login
? Select a server [Use arrows to move, type to filter]
> my-super ()
+ new server
创建Tanzu Kubernetes Cluster
配置参数
可以通过环境参数和建文件的办法来配置参数
使用export来改变环境参数,如
export CONTROL_PLANE_VM_CLASS=guaranteed-large
我们在实验中建立文件来指定参数:
[root@localhost tanzu]# cat config-cluster
DEFAULT_STORAGE_CLASS: tanzu-policy
STORAGE_CLASSES: tanzu-policy
WORKER_STORAGE_CLASS: tanzu-policy
WORKER_VM_CLASS: guaranteed-small
CONTROL_PLANE_VM_CLASS: guaranteed-small
CONTROL_PLANE_STORAGE_CLASS: tanzu-policy
SERVICE_CIDR: 100.64.0.0/13
CLUSTER_CIDR: 10.96.0.0/11
NAMESPACE: ns-dev
CLUSTER_PLAN: dev
SERVICE_DOMAIN: corp.tanzu
INFRASTRUCTURE_PROVIDER: tkg-service-vsphere
其中,Storage Classes
[root@localhost tanzu]# kubectl get sc
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
tanzu-policy csi.vsphere.vmware.com Delete Immediate true 30h
CLUSTER_PLAN 使用 dev, prod, 或者自定义的custom plan
VM_CLASS 使用在前面定义过的VM类
更多参数信息参考Configuration Parameters for Provisioning Tanzu Kubernetes Clusters
创建集群
- 查看现有可用Images
[root@localhost tanzu]# tanzu kubernetes-release get
NAME VERSION COMPATIBLE UPGRADEAVAILABLE
v1.19.7---vmware.1-tkg.2.f52f85a 1.19.7+vmware.1-tkg.2.f52f85a True
这个就是我们在前面导入到内容库的image
- 使用tanzu create命令创建集群
首先通过dry-run验证
[root@localhost tanzu]# tanzu cluster create my-cluster-01 --tkr v1.19.7---vmware.1-tkg.2.f52f85a --dry-run -f config-cluster
apiVersion: run.tanzu.vmware.com/v1alpha1
kind: TanzuKubernetesCluster
metadata:
annotations:
tkg/plan: dev
labels:
tkg.tanzu.vmware.com/cluster-name: my-cluster-01
name: my-cluster-01
namespace: ns-dev
spec:
distribution:
version: 1.19.7+vmware.1-tkg.2.f52f85a
settings:
network:
cni:
name: antrea
pods:
cidrBlocks:
- 10.96.0.0/11
serviceDomain: corp.tanzu
services:
cidrBlocks:
- 100.64.0.0/13
storage:
classes:
- tanzu-policy
defaultClass: tanzu-policy
topology:
controlPlane:
class: guaranteed-small
count: 1
storageClass: tanzu-policy
workers:
class: guaranteed-small
count: 1
storageClass: tanzu-policy
生成集群
[root@localhost tanzu]# tanzu cluster create my-cluster-01 --tkr v1.19.7---vmware.1-tkg.2.f52f85a -f config-cluster
You are trying to create a cluster with kubernetes version '1.19.7+vmware.1-tkg.2.f52f85a' on vSphere with Tanzu, Please make sure virtual machine image for the same is available in the cluster content library.
Do you want to continue? [y/N]: y
Validating configuration...
Workload cluster 'my-cluster-01' created
创建成功,也可以在vCenter上面看到
以上。