What is Terraform ?

Terraform workflow

Let’s practice !

$ mkdir config terraform
├── config
└── terraform
2 directories, 0 files.
$ mkdir terraform/cluster$ cd terraform/cluster$ touch main.tf outputs.tf provider.tf
├── config
└── terraform
└── cluster
├── main.tf
├── outputs.tf
└── provider.tf
3 directories, 3 files
$ export AWS_ACCESS_KEY_ID=xxxx$ export AWS_SECRET_ACCESS_KEY=xxxx$ terraform initInitializing the backend...Initializing provider plugins...
- Finding scaleway/scaleway versions matching "~> 2.2.1"...
- Installing scaleway/scaleway v2.2.3...
- Installed scaleway/scaleway v2.2.3 (signed by a HashiCorp partner, key ID F5BF26CADF6F9614)
...Terraform has been successfully initialized!...
$ terraform initInitializing modules...
Downloading git::ssh://git@github.com/vmarlier/terraform-modules.git?ref=main for kapsule...
- kapsule in .terraform/modules/kapsule/kapsule
...Terraform has been successfully initialized!...$ terraform validateSuccess! The configuration is valid.$ terraform fmt
$ export SCW_ACCESS_KEY=xxxx$ export SCW_SECRET_KEY=xxxx

$ terraform plan
Terraform will perform the following actions: # module.kapsule.scaleway_k8s_cluster.cluster will be created
+ resource "scaleway_k8s_cluster" "cluster" {
...
+ name = "fr-production"
+ type = "kapsule"
+ version = "1.22.9"
...
}
# module.kapsule.scaleway_k8s_pool.node_pool["default"] will be created
+ resource "scaleway_k8s_pool" "node_pool" {
...
+ name = "default"
+ node_type = "DEV1-M"
...
}
Plan: 2 to add, 0 to change, 0 to destroy.Changes to Outputs:
+ cluster_ca_certificate = (sensitive value)
+ cluster_host = (sensitive value)
+ cluster_id = (known after apply)
+ cluster_kubeconfig = (sensitive value)
+ cluster_token = (sensitive value)

Let’s create the cluster !

$ terraform apply...Plan: 2 to add, 0 to change, 0 to destroy....Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yesmodule.kapsule.scaleway_k8s_cluster.cluster: Creating...
module.kapsule.scaleway_k8s_cluster.cluster: Creation complete after 6s [id=fr-par/eccd3532-75b7-4ef2-9a7a-adaa854d4175]
module.kapsule.scaleway_k8s_pool.node_pool["default"]: Creating...
module.kapsule.scaleway_k8s_pool.node_pool["default"]: Still creating... [10s elapsed]
module.kapsule.scaleway_k8s_pool.node_pool["default"]: Still creating... [20s elapsed]
module.kapsule.scaleway_k8s_pool.node_pool["default"]: Still creating... [30s elapsed]
module.kapsule.scaleway_k8s_pool.node_pool["default"]: Still creating... [40s elapsed]
module.kapsule.scaleway_k8s_pool.node_pool["default"]: Still creating... [50s elapsed]
module.kapsule.scaleway_k8s_pool.node_pool["default"]: Creation complete after 56s [id=fr-par/d807679c-5aa4-44fc-a71b-341ca690567a]
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.Outputs:cluster_ca_certificate = <sensitive>
cluster_host = <sensitive>
cluster_id = "fr-par/eccd3532-75b7-4ef2-9a7a-adaa854d4175"
cluster_kubeconfig = <sensitive>
cluster_token = <sensitive>
$ make get-kubeconfigEnter the desired cluser: eccd3532-75b7-4ef2-9a7a-adaa854d4175
Enter the scaleway profile: miniature-fiesta
$ export KUBECONFIG=~/.kube/scaleway_fr-production$ kubectl cluster-infoKubernetes control plane is running at https://eccd3532-75b7-4ef2-9a7a-adaa854d4175.api.k8s.fr-par.scw.cloud:6443
CoreDNS is running at https://eccd3532-75b7-4ef2-9a7a-adaa854d4175.api.k8s.fr-par.scw.cloud:6443/api/v1/namespaces/kube-system/services/coredns:dns/proxy
$ kubectl get pods -n kube-systemNAME READY STATUS RESTARTS AGE
calico-kube-controllers-6f9fc8d66d-h7ddh 1/1 Running 0 13m
calico-node-mzpn5 1/1 Running 0 9m
coredns-56bf5f7789-th2sl 1/1 Running 0 13m
csi-node-blrfl 2/2 Running 0 9m
konnectivity-agent-sm2n6 1/1 Running 0 9m
kube-proxy-hcf7v 1/1 Running 0 9m
metrics-server-74cf4b5cf9-kx8vx 1/1 Running 0 13m
node-problem-detector-hqhw8 1/1 Running 0 9m

Conclusion

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐