I have one deployment running :
# kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
kubernetes-dashboard 4 4 4 4 131d
I can view the current deployment config using :
# kubectl get deployments kubernetes-dashboard -o yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "2"
creationTimestamp: 2017-02-03T16:04:04Z
generation: 5
labels:
app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: default
resourceVersion: "33197158"
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/kubernetes-dashboard
uid: 627d92b2-ea2a-11e6-a152-0050569b714e
spec:
replicas: 4
selector:
matchLabels:
app: kubernetes-dashboard
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
annotations:
scheduler.alpha.kubernetes.io/tolerations: |
[
{
"key": "dedicated",
"operator": "Equal",
"value": "master",
"effect": "NoSchedule"
}
]
creationTimestamp: null
labels:
app: kubernetes-dashboard
spec:
containers:
- args:
- --apiserver-host=http://172.29.219.6:8080
image: gcr.io/google_containers/kubernetes-dashboard-amd64:v1.5.0
imagePullPolicy: Always
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: 9090
scheme: HTTP
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 30
name: kubernetes-dashboard
ports:
- containerPort: 9090
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 4
observedGeneration: 5
replicas: 4
updatedReplicas: 4
Now I want to edit replicas: 4
on the fly. I know that one way to do it is :
kubectl edit deployment kubernetes-dashboard
But the above method open up a file that I then need to update manually. This becomes a problem for me since I want to automate editing these deployments using an external tool like a script or Ansible.
I was hoping to use something like this :
kubectl set replicas deployment/kubernetes-dashboard replicas=2
But seems like such a command is not supported. Looks like such a command is only supported for image
tag.
Is there any way I can update the replicas OR any other property if a deployment but just issuing a command (without having any editor involved)?
You can achieve this for deployments with this command:
kubectl scale deployment my-deployment --replicas 4
More info in the docs.
A more generic solution to this problem, if you happened to want to change a different piece of config, is to use:
kubectl patch deployment my-deployment -p '{"spec": {"replicas": 4}}'
This can be used to apply arbitrary partial config updates to any resource. Docs.