mirror of
https://github.com/jbowdre/vsphere-k8s.git
synced 2024-11-25 09:12:17 +00:00
Compare commits
3 commits
82e5e61064
...
beb7a2feca
Author | SHA1 | Date | |
---|---|---|---|
beb7a2feca | |||
7c671e1ee5 | |||
eea0551bca |
5 changed files with 13 additions and 10 deletions
|
@ -1,8 +1,13 @@
|
||||||
# Vanilla Kubernetes on VMware vSphere
|
# Vanilla Kubernetes on VMware vSphere
|
||||||
|
|
||||||
|
## Prerequisites
|
||||||
|
1. [Packer](https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli) installed on your system
|
||||||
|
2. Account in vSphere with [appropriate privileges](https://developer.hashicorp.com/packer/plugins/builders/vsphere/vsphere-iso#required-vsphere-privileges)
|
||||||
|
3. [Ubuntu Server 20.04 installation ISO](https://releases.ubuntu.com/20.04.5/) copied to a vSphere datastore
|
||||||
|
|
||||||
## Packer
|
## Packer
|
||||||
1. `cd packer`.
|
1. `cd packer`.
|
||||||
2. Copy `linux-server.example.pkrvars.hcl` to `linux-server.auto.pkrvars.hcl` and update it as appropriate for your environment.
|
2. Copy `ubuntu-k8s.example.pkrvars.hcl` to `ubuntu-k8s.auto.pkrvars.hcl` and update it as appropriate for your environment.
|
||||||
2. Put the SSH private key which corresponds to the `build_key` variable in `packer_cache/ssh_private_key_packer.pem`.
|
2. Put the SSH private key which corresponds to the `build_key` variable in `packer_cache/ssh_private_key_packer.pem`.
|
||||||
3. Place any needed internal CA PEM-formatted certs (with `.cer` file extension) in `certs/`.
|
3. Place any needed internal CA PEM-formatted certs (with `.cer` file extension) in `certs/`.
|
||||||
4. Run it with `packer build -on-error=abort -force .`.
|
4. Run it with `packer build -on-error=abort -force .`.
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
#!/bin/bash -eu
|
#!/bin/bash -eu
|
||||||
chmod 600 ~/.ssh/id_ed25519
|
|
||||||
|
|
||||||
echo ">> Installing Kubernetes components..."
|
echo ">> Installing Kubernetes components..."
|
||||||
|
|
||||||
# Configure and enable kernel modules
|
# Configure and enable kernel modules
|
||||||
|
|
|
@ -162,11 +162,6 @@ build {
|
||||||
destination = "/tmp"
|
destination = "/tmp"
|
||||||
}
|
}
|
||||||
|
|
||||||
provisioner "file" {
|
|
||||||
source = "packer_cache/ssh_private_key_packer.pem"
|
|
||||||
destination = "/home/${var.build_username}/.ssh/id_ed25519"
|
|
||||||
}
|
|
||||||
|
|
||||||
provisioner "shell" {
|
provisioner "shell" {
|
||||||
execute_command = "export KUBEVERSION=${var.k8s_version}; bash {{ .Path }}"
|
execute_command = "export KUBEVERSION=${var.k8s_version}; bash {{ .Path }}"
|
||||||
expect_disconnect = true
|
expect_disconnect = true
|
||||||
|
|
|
@ -137,6 +137,7 @@ resource "vsphere_virtual_machine" "control" {
|
||||||
"echo export K8S_POD_CIDR=\"'${var.k8s-pod-cidr}'\" >> env.txt",
|
"echo export K8S_POD_CIDR=\"'${var.k8s-pod-cidr}'\" >> env.txt",
|
||||||
"echo export K8S_CLUSTER_NAME=\"'${var.k8s-cluster-name}'\" >> env.txt",
|
"echo export K8S_CLUSTER_NAME=\"'${var.k8s-cluster-name}'\" >> env.txt",
|
||||||
"echo export K8S_CONTROLPLANE_VIP=\"'${var.k8s-controlplane-vip}'\" >> env.txt",
|
"echo export K8S_CONTROLPLANE_VIP=\"'${var.k8s-controlplane-vip}'\" >> env.txt",
|
||||||
|
"echo export K8S_CONTROLPLANE_COUNT=\"'${var.vm-control-count}'\" >> env.txt",
|
||||||
"echo export KUBEVIP_VER=\"'${var.k8s-kubevip-version}'\" >> env.txt",
|
"echo export KUBEVIP_VER=\"'${var.k8s-kubevip-version}'\" >> env.txt",
|
||||||
"echo export K8S_NODE_COUNT=\"'${local.k8s-node-count}'\" >> env.txt",
|
"echo export K8S_NODE_COUNT=\"'${local.k8s-node-count}'\" >> env.txt",
|
||||||
"echo export VCENTER_SERVER=\"'${var.vsphere-server}'\" >> env.txt",
|
"echo export VCENTER_SERVER=\"'${var.vsphere-server}'\" >> env.txt",
|
||||||
|
|
|
@ -343,10 +343,14 @@ datacenters = "${VCENTER_DATACENTER}"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
kubectl create secret generic vsphere-config-secret --from-file=csi-vsphere.conf --namespace=vmware-system-csi
|
kubectl create secret generic vsphere-config-secret --from-file=csi-vsphere.conf --namespace=vmware-system-csi
|
||||||
if kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/vsphere-csi-driver/v2.7.0/manifests/vanilla/vsphere-csi-driver.yaml; then
|
wget "https://raw.githubusercontent.com/kubernetes-sigs/vsphere-csi-driver/v2.7.0/manifests/vanilla/vsphere-csi-driver.yaml"
|
||||||
|
if [ "${K8S_CONTROLPLANE_COUNT}" -lt 3 ]; then
|
||||||
|
sed -i 's/replicas: 3/replicas: 1/' vsphere-csi-driver.yaml
|
||||||
|
fi
|
||||||
|
if kubectl apply -f vsphere-csi-driver.yaml; then
|
||||||
echo ">> Cluster initialization complete!"
|
echo ">> Cluster initialization complete!"
|
||||||
touch .k8s-cluster-success
|
touch .k8s-cluster-success
|
||||||
rm -f csi-vsphere.conf discovery.yaml env.txt kubeadminit.yaml initialize-controlplane.sh
|
rm -f csi-vsphere.conf discovery.yaml env.txt kubeadminit.yaml initialize-controlplane.sh vsphere-csi-driver.yaml
|
||||||
else
|
else
|
||||||
echo ">> [ERROR] Failed to configure CSI! <<"
|
echo ">> [ERROR] Failed to configure CSI! <<"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue