Command for Those Who Don’t Want Use Kubectl Edit

Photo by Erik Mclean on Unsplash

Introduction

Let’s test this !

Run example deployment

root@vagrant:/home/vagrant# kubectl create deployment nginx --image=spy86/nginx:latest
deployment.apps/nginx created
root@vagrant:/home/vagrant# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx-6465f7cb5d-phgmr 1/1 Running 0 8s
root@vagrant:/home/vagrant# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 10s
root@vagrant:/home/vagrant#

Modify the container image

root@vagrant:/home/vagrant# kubectl patch deployment nginx -p '{"spec":{"template":{"spec":{"containers":[{"name":"nginx","image":"spy86/nginx:147"}]}}}}'
deployment.apps/nginx patched
root@vagrant:/home/vagrant#
root@vagrant:/home/vagrant# kubectl describe deploy nginx | grep Image:
Image: spy86/nginx:147

Change the number of replicas

root@vagrant:/home/vagrant# kubectl patch deployment nginx -p '{"spec":{"replicas":10}}'
deployment.apps/nginx patched
root@vagrant:/home/vagrant# kubectl get po
NAME READY STATUS RESTARTS AGE
nginx-9ddb798cf-mrjds 1/1 Running 0 3m22s
nginx-9ddb798cf-rrhvv 1/1 Running 0 101s
nginx-9ddb798cf-fpzcw 1/1 Running 0 101s
nginx-9ddb798cf-dcg8d 1/1 Running 0 101s
nginx-9ddb798cf-rb5nc 1/1 Running 0 101s
nginx-9ddb798cf-fn5s4 1/1 Running 0 101s
nginx-9ddb798cf-69k48 1/1 Running 0 101s
nginx-9ddb798cf-hhd74 1/1 Running 0 101s
nginx-9ddb798cf-n4ww9 1/1 Running 0 101s
nginx-9ddb798cf-fzrk9 1/1 Running 0 101s

Change the Service Type

root@vagrant:/home/vagrant# kubectl expose deployment nginx --type=ClusterIP --name=nginx --port=80
service/nginx exposed
root@vagrant:/home/vagrant# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 13m
nginx ClusterIP 10.152.183.209 <none> 80/TCP 6s

One-liner to change service Type to NodePort

root@vagrant:/home/vagrant# kubectl get svc nginx -o jsonpath='{.spec.type}'
ClusterIP
root@vagrant:/home/vagrant# kubectl patch service nginx -p '{"spec":{"type":"NodePort"}}'
service/nginx patched
root@vagrant:/home/vagrant# kubectl get svc nginx -o jsonpath='{.spec.type}'
NodePort
root@vagrant:/home/vagrant# kubectl get svc nginx -o jsonpath='{.spec.ports[0].nodePort}'
30222
root@vagrant:/home/vagrant#
Source: https://giphy.com/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.