mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-31 14:44:50 +00:00
client-go: Update CRUD example
This updates the create-update-delete-deployment example with the following: Add rollback step to demonstrate rolling back deployments with client-go. Modify the for-loops used in both Update steps to Get() the latest version of the Deployment from the server before attempting Update(). This is necessary because the object returned by Create() does not have the new resourceVersion, causing the initial Update() to always fail due to conflicting resource versions. Putting the Get() at the top of the loop seems to fix this bug. Make -kubeconfig flag optional if config is in default location, using the same method found in the out-of-cluster example. Patch is motivated by effort to improve client-go examples. Signed-off-by: John Kelly <jekohk@gmail.com> Kubernetes-commit: ce73088a718c30d8a3577f5d0521584b9c201e69
This commit is contained in:
committed by
Kubernetes Publisher
parent
accfc9b01e
commit
4e80b27156
@@ -22,21 +22,28 @@ go build -o ./app
|
||||
Now, run this application on your workstation with your local kubeconfig file:
|
||||
|
||||
```
|
||||
./app
|
||||
# or specify a kubeconfig file with flag
|
||||
./app -kubeconfig=$HOME/.kube/config
|
||||
```
|
||||
|
||||
Running this command will execute the following operations on your cluster:
|
||||
|
||||
1. **Create Deployment:** This will create a 2 replica Deployment. Verify with
|
||||
`kubectl get pods`.
|
||||
1. **Create Deployment:** This will create a 2 replica Deployment with
|
||||
annotation `fizz=buzz`. Verify with `kubectl get pods`.
|
||||
2. **Update Deployment:** This will update the Deployment resource created in
|
||||
previous step to set the replica count to 1 and add annotations. You are
|
||||
previous step to set the replica count to 1 and update annotations. You are
|
||||
encouraged to inspect the retry loop that handles conflicts. Verify the new
|
||||
replica count and `foo=bar` annotation with `kubectl describe deployment
|
||||
demo`.
|
||||
3. **List Deployments:** This will retrieve Deployments in the `default`
|
||||
3. **Rollback Deployment:** This will rollback the Deployment to the last
|
||||
revision, in this case the revision created in Step 1. Use `kubectl describe`
|
||||
to verify the original annotation `fizz=buzz`. Also note the replica count
|
||||
is still 1; this is because a Deployment revision is created if and only
|
||||
if the Deployment's pod template (`.spec.template`) is changed.
|
||||
4. **List Deployments:** This will retrieve Deployments in the `default`
|
||||
namespace and print their names and replica counts.
|
||||
4. **Delete Deployment:** This will delete the Deployment object and its
|
||||
5. **Delete Deployment:** This will delete the Deployment object and its
|
||||
dependent ReplicaSet resource. Verify with `kubectl get deployments`.
|
||||
|
||||
Each step is separated by an interactive prompt. You must hit the
|
||||
@@ -55,6 +62,10 @@ Updating deployment...
|
||||
Updated deployment...
|
||||
-> Press Return key to continue.
|
||||
|
||||
Rolling back deployment...
|
||||
Rolled back deployment...
|
||||
-> Press Return key to continue.
|
||||
|
||||
Listing deployments in namespace "default":
|
||||
* demo-deployment (1 replicas)
|
||||
-> Press Return key to continue.
|
||||
|
Reference in New Issue
Block a user