I am using kubernetes imperative way instead of declarative. As there are many parameters changing regularly and can't update the yaml file every time.
For creating a deployment, we use this
kubectl create deployment nginx --image=nginx:1.7.1
This is fine for public images. But for provate images, we need to pass credentials data using secrets.As in link If it is yaml file, we keep in the file below line.
imagePullSecrets:
- name: regcred
But, how to pass this data for below type of line.?
kubectl create deployment nginx --image=nginx:1.7.1
You can still manage Kubernetes with kubectl
the same way using configuration files. There's no need to resort to complicated command line arguments. Just create your deployment manifest like normal. For example:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.7.1
ports:
- containerPort: 80
imagePullSecrets:
- name: regcred
Then imperatively commit the manifest to the Kubernetes API Server:
kubectl create -f deployment.yml
There is a possibility to Add ImagePullSecrets to a service account.
This might help you:
If the pod does not have a ServiceAccount set, it sets the ServiceAccount to default. It ensures that the ServiceAccount referenced by the pod exists, and otherwise rejects it. If the pod does not contain any ImagePullSecrets, then ImagePullSecrets of the ServiceAccount are added to the pod.
patch serviceaccount you use and set imagePullSecrets equal to your chosen secret.
kubectl patch serviceaccount <account> -p '{"imagePullSecrets": [{"name": "regcred"}]}'
You may also find interesting Automatically use secret when pulling from private registry thread.
Here example for adding image-pull-secrets in command line
kubectl run hello-world -it --restart=Never --image=nginx:1.7.1 --image-pull-secrets=regcred
For overriding, you can use :
kubectl run <name> -it --restart=Never --image=<private image> --overrides='{ "apiVersion": "v1", "spec": {"imagePullSecrets": [{"name": "<secret>"}]} }'