-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands_for_labs.txt
111 lines (81 loc) · 3.22 KB
/
commands_for_labs.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Lab 1 - Setting Up Your Environment for Developing Kubernetes Operators
## Install Docker
sudo yum -y install docker
sudo usermod -a -G docker cloud_user
newgrp docker
sudo systemctl enable docker.service
sudo systemctl start docker.service
## Install Go
wget https://go.dev/dl/go1.19.3.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.19.3.linux-amd64.tar.gz
sudo chmod +x /usr/local/go
export PATH=$PATH:/usr/local/go/bin
## Install kubectl
curl -o kubectl https://s3.us-west-2.amazonaws.com/amazon-eks/1.23.7/2022-06-29/bin/linux/amd64/kubectl
chmod +x kubectl
cp kubectl /usr/local/bin/
## Install Kind
go install sigs.k8s.io/[email protected]
sudo cp go/bin/kind /usr/local/bin/
kind create cluster --name operator-dev
kubectl cluster-info --context kind-operator-dev
## Install Operator SDK and enable OLM
export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)
export OS=$(uname | awk '{print tolower($0)}')
export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.25.0
curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}
chmod +x operator-sdk_${OS}_${ARCH} && sudo mv operator-sdk_${OS}_${ARCH} /usr/local/bin/operator-sdk
operator-sdk olm install
## Login to docker hub
docker login
# Lab 2 - Creating Your First Kubernetes Operator
## Create the Operator project directory:
mkdir -p projects/memcached-operator
## Move into the project directory
cd projects/memcached-operator
## Enable the Go Modules
export PATH=$PATH:/usr/local/go/bin
export GO111MODULE=on
## Create the Operator project
operator-sdk init --domain=example.com --repo=github.com/example-inc/memcached-operator
## Create the API and Controller
operator-sdk create api --group cache --version v1alpha1 --kind Memcached --plugins="deploy-image/v1-alpha" --image=memcached:1.4.36-alpine --image-container-command="memcached,-m=64,modern,-v" --run-as-user="1001"
## Define the API
vim api/v1alpha1/memcached_types.go
Change from:
// +kubebuilder:validation:Maximum=3
To:
// +kubebuilder:validation:Maximum=5
## Update code:
make generate
## Generate CRD Manifests:
make manifests
## Log into Docker Hub (Must make an account. Use link that is provided.)
docker login
## Export your operator image
export IMG=docker.io/<your_username>/<operator_name>:v0.0.1
## Make the memcached-operator-system your current namespace
kubectl config set-context --current --namespace=memcached-operator-system
## Make the operator image
make docker-build IMG=$IMG
## Push your operator image to docker hub
make docker-push IMG=$IMG
## Deploy your Operator
make deploy IMG=$IMG
## Check the deployment
kubectl get deployment
## Create a Memcached Custom Resource
## Edit the cache_v1alpha1_memcached.yaml file and change the size to 3
vim config/samples/cache_v1alpha1_memcached.yaml
## Apply the CR
kubectl apply -f config/samples/cache_v1alpha1_memcached.yaml
## Check the deployment
kubectl get deployment
kubectl get pods
## Change the Size of the deployment from to 5
vim config/samples/cache_v1alpha1_memcached.yaml
## Apply the changes
kubectl apply -f config/samples/cache_v1alpha1_memcached.yaml
## Check the deployment
kubectl get deployment
kubectl get pods